--Go to Firestore data type conversion https://godoc.org/cloud.google.com/go/firestore#DocumentRef.Create
--Firestore to Go data type conversion https://godoc.org/cloud.google.com/go/firestore#DocumentSnapshot.DataTo
https://firebase.google.com/docs/firestore/manage-data/data-types?hl=ja
Go | Firestore |
---|---|
bool | Bool |
string | String |
int, int8, int16, int32 and int64 | Integer |
uint8, uint16 and uint32 | Integer |
uint, uint64 and uintptr | [^6]No good |
float32 and float64 | Double |
[]byte | Bytes |
time.Time and [^7]*ts.Timestamp | Timestamp |
[^3]*latlng.LatLng | GeoPoint |
Slices | Array |
*firestore.DocumentRef | Reference |
Maps and structs | Map |
All types of nil | Null |
[^ 6]: Because it may have a value that cannot be represented by int64, which is the basis of the integer type. [^ 7]: ts package: "github.com/golang/protobuf/ptypes/timestamp"
Firestore | Go |
---|---|
Null | nil |
Boolean value(Bool) | bool |
String(String) | string |
integer(Integer) | [^1]int64 |
Floating point number(Double) | [^2]float64 |
Part-Time Job(Bytes) | []byte |
Date and time(Timestamp) | time.Time |
Geographic coordinates(GeoPoint) | [^3]*latlng.LatLng |
Array(Arrays ) | [^4][]interface{} |
map(Maps) | [^5]map[string]interface{} |
reference(References) | *firestore.DocumentRefs |
[^ 1]: Integer types other than uint, uint64, uintptr (regardless of signed or unsigned) are allowed when set in a structure field. The overflow is detected as an error. [^ 2]: Float32 is also allowed when set in a struct field. The overflow is detected as an error. [^ 3]: latlng package: "google.golang.org/genproto/googleapis/type/latlng" [^ 4]: When set in a structure field, it is recursively entered as a slice or array of any type. Slice will be resized to fit the input value. In an array, the surplus elements are filled with 0, and conversely, if the array is too short, the remainder of the input value is deleted. [^ 5]: When set in the structure field, the key is a string only, the value can be of any type and is entered recursively.
Recommended Posts