package model import ( "github.com/mizuki1412/go-core-kit/service/configkit" "reflect" ) // Header WMS-ZJ通用Header type Header struct { ContentType string `map:"Content-Type"` Cookie string `map:"Cookie"` UserAgent string `map:"User-Agent"` } func NewHeader() *Header { header := new(Header) header.ContentType = "application/x-www-form-urlencoded; charset=UTF-8" header.Cookie = "JSESSIONID=" + configkit.GetString("wms.token", "") header.UserAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36" return header } func (th *Header) GenReqParam() map[string]string { return th.structToMap() } func (th *Header) structToMap() map[string]string { result := make(map[string]string) t := reflect.TypeOf(*th) v := reflect.ValueOf(*th) for i := 0; i < t.NumField(); i++ { field := t.Field(i) value := v.Field(i) // Use the tag value as the key in the map, if it exists; otherwise, use the field name. tag := field.Tag.Get("map") if tag == "" { tag = field.Name } result[tag] = value.String() } return result }