ソース
-
Go から Firestore のデータ型変換
https://godoc.org/cloud.google.com/go/firestore#DocumentRef.Create -
Firestore から Go のデータ型変換
https://godoc.org/cloud.google.com/go/firestore#DocumentSnapshot.DataTo
Firestoreのデータ型
Go から Firestore のデータ型変換
| Go | Firestore |
|---|---|
| bool | Bool |
| string | String |
| int, int8, int16, int32 and int64 | Integer |
| uint8, uint16 and uint32 | Integer |
| uint, uint64 and uintptr | 1だめ |
| float32 and float64 | Double |
| []byte | Bytes |
| time.Time and 2*ts.Timestamp | Timestamp |
| 3*latlng.LatLng | GeoPoint |
| Slices | Array |
| *firestore.DocumentRef | Reference |
| Maps and structs | Map |
| あらゆる型のnil | Null |
Firestore から Go のデータ型変換
| Firestore | Go |
|---|---|
| Null | nil |
| ブール値 (Bool) | bool |
| 文字列 (String) | string |
| 整数 (Integer) | 4int64 |
| 浮動小数点数 (Double) | 5float64 |
| バイト (Bytes) | []byte |
| 日時 (Timestamp) | time.Time |
| 地理的座標 (GeoPoint) | 3*latlng.LatLng |
| 配列 (Arrays ) | 6[]interface{} |
| マップ (Maps) | 7map[string]interface{} |
| 参照 (References) | *firestore.DocumentRefs |
-
整数型の基礎となるint64では表現できない値をもつ可能性があるため。 ↩
-
tsパッケージ:"github.com/golang/protobuf/ptypes/timestamp" ↩
-
latlngパッケージ:"google.golang.org/genproto/googleapis/type/latlng" ↩ ↩2
-
構造体フィールドにセットする場合、uint, uint64, uintptr 以外の整数型(signedやunsignedによらず)が許可されます。オーバーフローはエラーとして検出されます。 ↩
-
構造体フィールドにセットする場合、float32も許可されます。オーバーフローはエラーとして検出されます。 ↩
-
構造体フィールドにセットする場合、任意の型のsliceまたはarrayとして、再帰的に入力されます。Sliceは入力値に合わせてリサイズされます。配列(array)では余った要素は0で満たされ、逆に配列が短すぎる場合は入力値の余りは削除されます。 ↩
-
構造体フィールドにセットする場合、キーは文字列のみ、値は任意の型が許可され、再帰的に入力されます。 ↩