interface to struct

This commit is contained in:
poiuty 2023-05-11 13:42:01 +03:00
parent 12e5ac6f68
commit db66cde2fe

View file

@ -78,13 +78,15 @@ func broadcast() {
func sendMessage(message []byte, decode bool) { func sendMessage(message []byte, decode bool) {
chanel := "" chanel := ""
if decode { if decode {
var input map[string]interface{} input := struct {
Chanel string `json:"chanel"`
}{}
if err := json.Unmarshal(message, &input); err != nil { if err := json.Unmarshal(message, &input); err != nil {
fmt.Println("json error: ", err.Error()) fmt.Println("json error: ", err.Error())
return return
} }
if input["chanel"] != nil { if input.Chanel != "" {
chanel = input["chanel"].(string) chanel = input.Chanel
} }
} }