import ( "fmt" "google.golang.org/appengine/datastore" ) func main() { key := datastore.NewKey(ctx, "Person", "johndoe", 0, nil) encodedKey := datastore.KeyEncode(ctx, key) fmt.Println(encodedKey) }
import ( "fmt" "google.golang.org/appengine/datastore" ) func main() { keys := []*datastore.Key{ datastore.NewKey(ctx, "Person", "johndoe", 0, nil), datastore.NewKey(ctx, "Person", "janedoe", 0, nil), } encodedKeys := make([]string, len(keys)) for i, key := range keys { encodedKeys[i] = datastore.KeyEncode(ctx, key) } fmt.Println(encodedKeys) }This code creates a slice of datastore keys for two Person entities, then encodes each key using the datastore.KeyEncode function. The resulting encoded keys are stored in a slice of strings, which is printed to the console.