| 1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- package utils
- import (
- "github.com/gogf/gf/frame/g"
- "github.com/gogf/gf/net/ghttp"
- "github.com/hashicorp/go-uuid"
- )
- var UHttp *HttpUtil
- func init() {
- UHttp = NewHttpUtil()
- }
- type HttpUtil struct {
- }
- func NewHttpUtil() *HttpUtil {
- return &HttpUtil{}
- }
- const (
- MIMEJSON = "application/json"
- MIMEHTML = "text/html"
- MIMEXML = "application/xml"
- MIMEXML2 = "text/xml"
- MIMEPlain = "text/plain"
- MIMEPOSTForm = "application/x-www-form-urlencoded"
- MIMEMultipartPOSTForm = "multipart/form-data"
- MIMEPROTOBUF = "application/x-protobuf"
- MIMEMSGPACK = "application/x-msgpack"
- MIMEMSGPACK2 = "application/msgpack"
- MIMEYAML = "application/x-yaml"
- )
- func (s *HttpUtil) HttpClient(contentType string, system string, serviceName string) *ghttp.Client {
- uid, _ := uuid.GenerateUUID()
- client := g.Client()
- client.SetHeader("Content-Type", contentType)
- client.SetHeader("requestId", uid)
- client.SetHeader("sourceSystem", system)
- client.SetHeader("serviceName", serviceName)
- return client
- }
|