mirror of
https://github.com/Monibuca/engine.git
synced 2025-11-03 10:51:03 +08:00
完善反序列化数字类型
This commit is contained in:
@@ -1,11 +1,9 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"go.uber.org/zap"
|
||||
@@ -88,13 +86,13 @@ func (config Config) Unmarshal(s any) {
|
||||
}
|
||||
child.Unmarshal(fv)
|
||||
} else {
|
||||
// 修复类型为Uint16的反射序列化问题。
|
||||
switch fv.Type().Kind() {
|
||||
case reflect.Uint16:
|
||||
val := fmt.Sprintf("%d", value)
|
||||
uintVal, _ := strconv.Atoi(val)
|
||||
fv.SetUint(uint64(uintVal))
|
||||
break
|
||||
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
|
||||
fv.SetUint(value.Uint())
|
||||
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
||||
fv.SetInt(value.Int())
|
||||
case reflect.Float32, reflect.Float64:
|
||||
fv.SetFloat(value.Float())
|
||||
default:
|
||||
fv.Set(value)
|
||||
}
|
||||
|
||||
@@ -121,7 +121,7 @@ func (cfg *Engine) OnEvent(event any) {
|
||||
time.Sleep(time.Second * 5)
|
||||
continue
|
||||
}
|
||||
err = wsutil.WriteClientMessage(conn, ws.OpText, []byte(cfg.Secret))
|
||||
err = wsutil.WriteClientMessage(conn, ws.OpText, []byte(`{"command":"init","secret":"123456"}`))
|
||||
if err != nil {
|
||||
time.Sleep(time.Second * 5)
|
||||
continue
|
||||
@@ -152,5 +152,5 @@ var Global = &Engine{
|
||||
Publish{true, true, false, 10, 0},
|
||||
Subscribe{true, true, false, 10},
|
||||
HTTP{ListenAddr: ":8080", CORS: true, mux: http.DefaultServeMux},
|
||||
false, true, true, true, "wss://console.monibuca.com:8080", "",
|
||||
false, true, true, true, "wss://console.monibuca.com", "",
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user