增加全局VNC与TELNET设置

This commit is contained in:
dushixiang
2021-02-10 21:56:05 +08:00
committed by dushixiang
parent 622fa65241
commit 25c3c6b929
11 changed files with 783 additions and 765 deletions

View File

@ -11,6 +11,7 @@ import (
"net"
"os"
"path/filepath"
"reflect"
"sort"
"strconv"
"strings"
@ -157,3 +158,27 @@ func Contains(s []string, str string) bool {
}
return false
}
func StructToMap(obj interface{}) map[string]interface{} {
t := reflect.TypeOf(obj)
v := reflect.ValueOf(obj)
if t.Kind() == reflect.Ptr {
// 如果是指针,则获取其所指向的元素
t = t.Elem()
v = v.Elem()
}
var data = make(map[string]interface{})
if t.Kind() == reflect.Struct {
// 只有结构体可以获取其字段信息
for i := 0; i < t.NumField(); i++ {
jsonName := t.Field(i).Tag.Get("json")
if jsonName != "" {
data[jsonName] = v.Field(i).Interface()
} else {
data[t.Field(i).Name] = v.Field(i).Interface()
}
}
}
return data
}