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) {
chanel := ""
if decode {
var input map[string]interface{}
input := struct {
Chanel string `json:"chanel"`
}{}
if err := json.Unmarshal(message, &input); err != nil {
fmt.Println("json error: ", err.Error())
return
}
if input["chanel"] != nil {
chanel = input["chanel"].(string)
if input.Chanel != "" {
chanel = input.Chanel
}
}