Encode returns an opaque representation of the key suitable for use in HTML and URLs. This is compatible with the Python and Java runtimes.
()
| 229 | // suitable for use in HTML and URLs. |
| 230 | // This is compatible with the Python and Java runtimes. |
| 231 | func (k *Key) Encode() string { |
| 232 | ref := keyToProto("", k) |
| 233 | |
| 234 | b, err := proto.Marshal(ref) |
| 235 | if err != nil { |
| 236 | panic(err) |
| 237 | } |
| 238 | |
| 239 | // Trailing padding is stripped. |
| 240 | return strings.TrimRight(base64.URLEncoding.EncodeToString(b), "=") |
| 241 | } |
| 242 | |
| 243 | // DecodeKey decodes a key from the opaque representation returned by Encode. |
| 244 | func DecodeKey(encoded string) (*Key, error) { |