package gateway import ( "git.sxidc.com/go-tools/utils/http_client" "net/http" ) type BuilderRequest interface { HttpMethod() string RequestUrl() string Request(request *http_client.Request) error Response() *http_client.Response } type PostRequest struct { Url string Headers map[string]string Body []byte response *http_client.Response } func (req *PostRequest) HttpMethod() string { return http.MethodPost } func (req *PostRequest) RequestUrl() string { return req.Url } func (req *PostRequest) Request(request *http_client.Request) error { response, err := request.Post(req.Url, req.Body, http_client.WithRequestHeaders(req.Headers)) if err != nil { return err } req.response = response return nil } func (req *PostRequest) Response() *http_client.Response { return req.response } type DeleteRequest struct { Url string Headers map[string]string PathParams map[string]string QueryParams map[string]string response *http_client.Response } func (req *DeleteRequest) HttpMethod() string { return http.MethodDelete } func (req *DeleteRequest) RequestUrl() string { return req.Url } func (req *DeleteRequest) Request(request *http_client.Request) error { response, err := request.Delete(req.Url, http_client.WithRequestHeaders(req.Headers), http_client.WithRequestPathParams(req.PathParams), http_client.WithRequestQueryParams(req.QueryParams)) if err != nil { return err } req.response = response return nil } func (req *DeleteRequest) Response() *http_client.Response { return req.response } type PutRequest struct { Url string Headers map[string]string Body []byte response *http_client.Response } func (req *PutRequest) HttpMethod() string { return http.MethodPut } func (req *PutRequest) RequestUrl() string { return req.Url } func (req *PutRequest) Request(request *http_client.Request) error { response, err := request.Put(req.Url, req.Body, http_client.WithRequestHeaders(req.Headers)) if err != nil { return err } req.response = response return nil } func (req *PutRequest) Response() *http_client.Response { return req.response } type GetRequest struct { Url string Headers map[string]string PathParams map[string]string QueryParams map[string]string response *http_client.Response } func (req *GetRequest) HttpMethod() string { return http.MethodGet } func (req *GetRequest) RequestUrl() string { return req.Url } func (req *GetRequest) Request(request *http_client.Request) error { response, err := request.Get(req.Url, http_client.WithRequestHeaders(req.Headers), http_client.WithRequestPathParams(req.PathParams), http_client.WithRequestQueryParams(req.QueryParams)) if err != nil { return err } req.response = response return nil } func (req *GetRequest) Response() *http_client.Response { return req.response }