package model import ( "cu-helper/cus-eng-con-sys/config" "reflect" ) // Header 工建请求通用Header type Header struct { ContentType string `map:"Content-Type"` Cookie string `map:"Cookie"` Sid string `map:"Sid"` UserAgent string `map:"User-Agent"` } func NewHeader(contentType string) *Header { header := new(Header) header.ContentType = contentType header.Cookie = "sid=" + config.Conf.Sid header.Sid = config.Conf.Sid 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 }