LoginSignup
9
6

More than 3 years have passed since last update.

FirestoreとGoのデータ型変換の関係

Posted at

ソース

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

  1. 整数型の基礎となるint64では表現できない値をもつ可能性があるため。 

  2. tsパッケージ:"github.com/golang/protobuf/ptypes/timestamp" 

  3. latlngパッケージ:"google.golang.org/genproto/googleapis/type/latlng" 

  4. 構造体フィールドにセットする場合、uint, uint64, uintptr 以外の整数型(signedやunsignedによらず)が許可されます。オーバーフローはエラーとして検出されます。 

  5. 構造体フィールドにセットする場合、float32も許可されます。オーバーフローはエラーとして検出されます。 

  6. 構造体フィールドにセットする場合、任意の型のsliceまたはarrayとして、再帰的に入力されます。Sliceは入力値に合わせてリサイズされます。配列(array)では余った要素は0で満たされ、逆に配列が短すぎる場合は入力値の余りは削除されます。 

  7. 構造体フィールドにセットする場合、キーは文字列のみ、値は任意の型が許可され、再帰的に入力されます。 

9
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
6