import ( "camlistore.org/pkg/blob" "camlistore.org/pkg/blob/ref" ) func main() { str := "sha1-9da39a3ee5e6b4b0d3255bfef95601890afd80709" blobRef := ref.Parse(str) isValid := blob.RefValid(blobRef) fmt.Printf("Is '%v' a valid blob reference? %v\n", str, isValid) }
import ( "camlistore.org/pkg/blob" "camlistore.org/pkg/blob/ref" ) func main() { refs := []string{ "sha1-3b5995cb5a7ca0d71264f13eae83cb1bfe46356f", // valid "sha1-xyz", // invalid "sha1-693244135b9a82212a54a85971d4d4f75d673fde", // valid "sha1-", // invalid } var validRefs []ref.BlobRef for _, strRef := range refs { blobRef := ref.Parse(strRef) if blob.RefValid(blobRef) { validRefs = append(validRefs, blobRef) } } fmt.Printf("Valid blob references: %v\n", validRefs) }This code sets up a list of blob references as strings, parses each one into a `ref.BlobRef` struct, and iterates through them. For each one, it calls `blob.RefValid()` to check if it is valid, and if so adds it to a new slice of valid references. The final output is a list of valid blob references. In both examples, the package library is `camlistore.org/pkg/blob`.