Skip to content

Commit

Permalink
Merge pull request #7 from riku6460/fix-json-unmarshal
Browse files Browse the repository at this point in the history
  • Loading branch information
Laica-Lunasys authored Feb 20, 2024
2 parents ec99bf6 + a46d285 commit 2994cd5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
8 changes: 4 additions & 4 deletions database/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ type Lockdown struct {

type PingResponse struct {
Online bool
Version VersionData `json:"version"`
Players PlayersData `json:"players"`
Description map[string]string `json:"description"`
Favicon string `json:"favicon"`
Version VersionData `json:"version"`
Players PlayersData `json:"players"`
Description interface{} `json:"description"`
Favicon string `json:"favicon"`
}

type VersionData struct {
Expand Down
9 changes: 8 additions & 1 deletion server/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,13 @@ func (s *grpcServer) Lockdown_PBtoDB(pbEntry *pb.Lockdown) *database.Lockdown {
}

func (s *grpcServer) Status_DBtoPB(dbEntry database.PingResponse) *pb.ServerStatus {
var description string
if str, ok := dbEntry.Description.(string); ok {
description = str
} else if m, ok := dbEntry.Description.(map[string]string); ok {
description = m["text"]
}

return &pb.ServerStatus{
Online: dbEntry.Online,
Version: &pb.ServerStatus_Version{
Expand All @@ -230,7 +237,7 @@ func (s *grpcServer) Status_DBtoPB(dbEntry database.PingResponse) *pb.ServerStat
Max: int32(dbEntry.Players.Max),
Online: int32(dbEntry.Players.Online),
},
Description: dbEntry.Description["text"],
Description: description,
Favicon: dbEntry.Favicon,
}
}
Expand Down

0 comments on commit 2994cd5

Please sign in to comment.