I use Go to build my game server. I am going to compare a time from time.Now()
and one from a Firestore field. How can I do that in Go?
playerDataSnap, err := Instace.FireStoreClient.Collection("PlayerData").Doc(playerUID).Get(Instace.Context)
if err != nil {
log.Printf("EventModeFee Get PlayerData Fail: %v", err)
return
}
playerData := playerDataSnap.Data()
if value, exist := playerData["EventPlayTimes"]; exist {
eventPlayTimes = value.(int64)
}
if discount_Subscribe > 0 {
if value, exist := playerData["SubscriptionExpiredDate"]; exist { //Get Subscribe expired time
var expireTimeStamp = value //<-------------timestamp from firestore field
if time.Now().Before(expireTimeStamp) {//<---------------expireTimeStamp is not a valid type, but How can I convert it to a valid type
isSubscribed = true
}
}
}
expireTimeStamp
is not a valid type, but how can I convert it to a valid one?
CodePudding user response:
It turns out that I can directly assert the timestamp from Firestore field to time.Time
with the following code:
if time.Now().Before(expireTimeStamp.(time.Time)) {
isSubscribed = true
}