package requests import ( "net/http" ) // Params 相关参数结构 type Params struct { // Query map[string][]string IOBody interface{} // Files []UploadFile ContentType string } // Session 的基本方法 type Session struct { client *http.Client params *Params } // TypeContent post类型参数 type TypeContent int const ( _ TypeContent = iota // TypeJSON 类型 TypeJSON = "application/json" // TypeXML 类型 TypeXML = "text/xml" // TypeURLENCODED 类型 TypeURLENCODED = "application/x-www-form-urlencoded" // TypeFormData 类型 TypeFormData = "multipart/form-data" ) // NewSession 创建Session func NewSession() *Session { return &Session{client: &http.Client{}, params: &Params{}} } // Get 请求 func (ses *Session) Get(url string) *Workflow { wf := NewWorkflow(ses) wf.Method = "GET" wf.SetURL(url) return wf } // Post 请求 func (ses *Session) Post(url string) *Workflow { wf := NewWorkflow(ses) wf.Method = "POST" wf.SetURL(url) return wf } // Put 请求 func (ses *Session) Put(url string) *Workflow { wf := NewWorkflow(ses) wf.Method = "PUT" wf.SetURL(url) return wf } // Patch 请求 func (ses *Session) Patch(url string) *Workflow { wf := NewWorkflow(ses) wf.Method = "PATCH" wf.SetURL(url) return wf } // Delete 请求 func (ses *Session) Delete(url string) *Workflow { wf := NewWorkflow(ses) wf.Method = "DELETE" wf.SetURL(url) return wf } // Head 请求 func (ses *Session) Head(url string) *Workflow { wf := NewWorkflow(ses) wf.Method = "HEAD" wf.SetURL(url) return wf } // Options 请求 func (ses *Session) Options(url string) *Workflow { wf := NewWorkflow(ses) wf.Method = "OPTIONS" wf.SetURL(url) return wf }