package main
import (
"encoding/json"
"fmt"
"reflect"
"strconv"
"time"
)
type ATest struct {
AAA string `json:"AAA" def:"123456"`
BBB time.Duration `json:"BBB" def:"8000000000"`
CCC bool `json:"CCC" def:"true"`
DDD uint64 `json:"DDD" def:"3000"`
EEE int64 `json:"EEE" def:"-6000"`
}
func setValue(v reflect.Value, defVal string) {
switch v.Kind() {
case reflect.String:
v.SetString(defVal)
break
case reflect.Bool:
tmp, err := strconv.ParseBool(defVal)
if err != nil {
golang通过reflect,tag设定参数值
最新推荐文章于 2024-09-12 00:09:48 发布