This commit is contained in:
shoopea 2019-05-31 11:18:43 +08:00
parent c2a8f9b022
commit d96c8efc54

23
obj.go
View File

@ -158,7 +158,8 @@ func addObjCastle(logo string, name string) (int64, error) {
} }
func getObjCastleID(s string) int64 { func getObjCastleID(s string) int64 {
c, _ := cacheObjCastle.Load(s) var c *ChatWarsCastle
c, _ = cacheObjCastle.Load(s)
return c.ObjID64 return c.ObjID64
} }
@ -243,16 +244,17 @@ func addObjGuild(tag string, name string) (int64, error) {
} }
func getObjGuildID(s string) int64 { func getObjGuildID(s string) int64 {
var g *ChatWarsGuild
if g, ok := cacheObjGuild.Load(s); ok { if g, ok := cacheObjGuild.Load(s); ok {
return g.ObjID64 return g.ObjID64
} else { } else {
objID64, err := addObjGuild(s, ``) objID64, err := addObjGuild(s, ``)
logOnError(err, "getObjGuildID") logOnError(err, "getObjGuildID")
g := new(ChatWarsGuild) n := new(ChatWarsGuild)
g.ObjID64 = objID64 n.ObjID64 = objID64
g.Tag = s n.Tag = s
g.Name = `` n.Name = ``
cacheObjGuild.Store(s, *g) cacheObjGuild.Store(s, *n)
return objID64 return objID64
} }
} }
@ -337,15 +339,16 @@ func addObjUser(name string) (int64, error) {
} }
func getObjUserID(s string) int64 { func getObjUserID(s string) int64 {
var u *ChatWarsUser
if u, ok := cacheObjUser.Load(s); ok { if u, ok := cacheObjUser.Load(s); ok {
return u.ObjID64 return u.ObjID64
} else { } else {
objID64, err := addObjUser(s) objID64, err := addObjUser(s)
logOnError(err, "getObjUserID") logOnError(err, "getObjUserID")
u := new(ChatWarsUser) n := new(ChatWarsUser)
u.ObjID64 = objID64 n.ObjID64 = objID64
u.Name = s n.Name = s
cacheObjUser.Store(s, *u) cacheObjUser.Store(s, *n)
return objID64 return objID64
} }
} }