The type datastore.ByteString
is really just a regular []byte
slice, see its declaration:
type ByteString []byte
The difference is that if you have a property of type ByteString
, AppEngine will try to index it by default. Since datastore index entires have limited length, the length of a ByteString
value can only be max 1500 bytes to be indexable.
ByteString
also doesn't have any additional methods which would add some benefit besides the indexability.
If you don't plan to index your property, simply use a []byte
. If you plan to index it because you want to search / filter by it, then you must use ByteString
. This can be useful if for example you want to store hashes of some content (e.g. a file), and you want to search for a file based on its content hash. In this case a ByteString
makes perfect sense and is most compact (compared to an alternative where you would store the hash as a string
being the hexadecimal representation).
Note that even if you use ByteString
, you can still make the property unindexed by using tags, e.g.:
type MyEntity struct {
Something datastore.ByteString `datastore:"something,noindex"`
}