Documentation ¶
Index ¶
- Constants
- func ListenAndServe(addr string, router http.Handler, option ServerOption) (es, e error)
- func ListenAndServeV2(addr string, router http.Handler, option ServerOption) (es, e error)
- func Redirect(w http.ResponseWriter, r *http.Request, url string)
- func SetHeader(w http.ResponseWriter, key, value string)
- func WriteBytes(w http.ResponseWriter, response interface{}) error
- func WriteJSON(w http.ResponseWriter, response interface{}) error
- func WriteXML(w http.ResponseWriter, response interface{}) error
- type Message
- func Connect(uri string, body io.Reader, opt RequestOption) (msg Message, err error)
- func Delete(uri string, body io.Reader, opt RequestOption) (msg Message, err error)
- func Get(uri string, opt RequestOption) (msg Message, err error)
- func GetJSON(v interface{}, uri string, opt RequestOption) (msg Message, err error)
- func GetXML(v interface{}, uri string, opt RequestOption) (msg Message, err error)
- func Head(uri string, opt RequestOption) (msg Message, err error)
- func Options(uri string, body io.Reader, opt RequestOption) (msg Message, err error)
- func Patch(uri string, body io.Reader, opt RequestOption) (msg Message, err error)
- func Post(uri string, body io.Reader, opt RequestOption) (msg Message, err error)
- func Put(uri string, body io.Reader, opt RequestOption) (msg Message, err error)
- func Trace(uri string, body io.Reader, opt RequestOption) (msg Message, err error)
- type RequestOption
- func (r *RequestOption) AcceptEncodingGZIP() *RequestOption
- func (r *RequestOption) AddCookie(c *http.Cookie) *RequestOption
- func (r *RequestOption) SetBasicAuth(username, password string) *RequestOption
- func (r *RequestOption) SetCert(certFile, keyFile string) *RequestOption
- func (r *RequestOption) SetContentType(v string) *RequestOption
- func (r *RequestOption) SetContentTypeJSON() *RequestOption
- func (r *RequestOption) SetContentTypeURL() *RequestOption
- func (r *RequestOption) SetContentTypeXML() *RequestOption
- func (r *RequestOption) SetHeader(k, v string) *RequestOption
- func (r *RequestOption) SetResponseHeaderTimeout(v time.Duration) *RequestOption
- func (r *RequestOption) SetTimeOut(v time.Duration) *RequestOption
- type ServerOption
- func (s *ServerOption) SetCertFile(path string) *ServerOption
- func (s *ServerOption) SetIdleTimeout(t time.Duration) *ServerOption
- func (s *ServerOption) SetKeyFile(path string) *ServerOption
- func (s *ServerOption) SetMaxHeaderBytes(n int) *ServerOption
- func (s *ServerOption) SetReadHeaderTimeout(t time.Duration) *ServerOption
- func (s *ServerOption) SetReadTimeout(t time.Duration) *ServerOption
- func (s *ServerOption) SetShutdownTimeout(t time.Duration) *ServerOption
- func (s *ServerOption) SetWriteTimeout(t time.Duration) *ServerOption
Constants ¶
const ( // ContentType header Content-Type ContentType = `Content-Type` // AcceptEncoding header Accept-Encoding AcceptEncoding = `Accept-Encoding` // ContentTypeURL application/x-www-form-urlencoded ContentTypeURL = `application/x-www-form-urlencoded; charset=utf-8` // ContentTypeJSON application/json ContentTypeJSON = `application/json; charset=utf-8` // ContentTypeXML application/xml ContentTypeXML = `application/xml; charset=utf-8` // ContentTypeMultipart multipart/form-data ContentTypeMultipart = `multipart/form-data` )
const
Variables ¶
This section is empty.
Functions ¶
func ListenAndServe ¶
func ListenAndServe(addr string, router http.Handler, option ServerOption) (es, e error)
ListenAndServe new server and start
func ListenAndServeV2 ¶
func ListenAndServeV2(addr string, router http.Handler, option ServerOption) (es, e error)
ListenAndServeV2 new http2 server and start
func SetHeader ¶
func SetHeader(w http.ResponseWriter, key, value string)
SetHeader set http response header
func WriteBytes ¶
func WriteBytes(w http.ResponseWriter, response interface{}) error
WriteBytes response bytes
func WriteJSON ¶
func WriteJSON(w http.ResponseWriter, response interface{}) error
WriteJSON response JSON data.
func WriteXML ¶
func WriteXML(w http.ResponseWriter, response interface{}) error
WriteXML response XML data.
Types ¶
type Message ¶
type Message struct { StatusCode int Body []byte Header http.Header // contains filtered or unexported fields }
Message HTTP response
func GetJSON ¶
func GetJSON(v interface{}, uri string, opt RequestOption) (msg Message, err error)
GetJSON HTTP request GET, response JSON
func GetXML ¶
func GetXML(v interface{}, uri string, opt RequestOption) (msg Message, err error)
GetXML HTTP request GET, response XML
func Head ¶
func Head(uri string, opt RequestOption) (msg Message, err error)
Head HTTP request HEAD
func (Message) Location ¶
Location returns the URL of the response's "Location" header, if present. Relative redirects are resolved relative to the Response's Request. ErrNoLocation is returned if no Location header is present.
type RequestOption ¶
type RequestOption struct { RequestTimeOut time.Duration ResponseHeaderTimeout time.Duration Headers map[string]string Cookies []*http.Cookie CertFile string KeyFile string // contains filtered or unexported fields }
RequestOption HTTP request option
func DefaultRequestOption ¶
func DefaultRequestOption() RequestOption
DefaultRequestOption default request option
func (*RequestOption) AcceptEncodingGZIP ¶
func (r *RequestOption) AcceptEncodingGZIP() *RequestOption
AcceptEncodingGZIP Accept-Encoding gzip
func (*RequestOption) AddCookie ¶
func (r *RequestOption) AddCookie(c *http.Cookie) *RequestOption
AddCookie adds a cookie to the request.
func (*RequestOption) SetBasicAuth ¶
func (r *RequestOption) SetBasicAuth(username, password string) *RequestOption
SetBasicAuth sets the request's Authorization header to use HTTP Basic Authentication with the provided username and password.
func (*RequestOption) SetCert ¶
func (r *RequestOption) SetCert(certFile, keyFile string) *RequestOption
SetCert set request cert & key file
func (*RequestOption) SetContentType ¶
func (r *RequestOption) SetContentType(v string) *RequestOption
SetContentType set Content-Type
func (*RequestOption) SetContentTypeJSON ¶
func (r *RequestOption) SetContentTypeJSON() *RequestOption
SetContentTypeJSON Content-Type json
func (*RequestOption) SetContentTypeURL ¶
func (r *RequestOption) SetContentTypeURL() *RequestOption
SetContentTypeJSON Content-Type json
func (*RequestOption) SetContentTypeXML ¶
func (r *RequestOption) SetContentTypeXML() *RequestOption
SetContentTypeJSON Content-Type json
func (*RequestOption) SetHeader ¶
func (r *RequestOption) SetHeader(k, v string) *RequestOption
SetHeader set header
func (*RequestOption) SetResponseHeaderTimeout ¶
func (r *RequestOption) SetResponseHeaderTimeout(v time.Duration) *RequestOption
SetResponseHeaderTimeout set response header timeout
func (*RequestOption) SetTimeOut ¶
func (r *RequestOption) SetTimeOut(v time.Duration) *RequestOption
SetTimeOut set request timeout
type ServerOption ¶
type ServerOption struct { CertFile string KeyFile string // ReadHeaderTimeout is the amount of time allowed to read request headers ReadHeaderTimeout time.Duration // ReadTimeout is the maximum duration for reading the entire // request, including the body. ReadTimeout time.Duration // WriteTimeout is the maximum duration before timing out // writes of the response. WriteTimeout time.Duration // IdleTimeout is the maximum amount of time to wait for the // next request when keep-alives are enabled. IdleTimeout time.Duration // MaxHeaderBytes controls the maximum number of bytes the // server will read parsing the request header's keys and // values, including the request line. It does not limit the // size of the request body. // If zero, DefaultMaxHeaderBytes is used. MaxHeaderBytes int ShutdownTimeout time.Duration }
ServerOption serve option
func DefaultServerOption ¶
func DefaultServerOption() ServerOption
func (*ServerOption) SetCertFile ¶
func (s *ServerOption) SetCertFile(path string) *ServerOption
SetCertFile set CertFile
func (*ServerOption) SetIdleTimeout ¶
func (s *ServerOption) SetIdleTimeout(t time.Duration) *ServerOption
SetIdleTimeout set IdleTimeout
func (*ServerOption) SetKeyFile ¶
func (s *ServerOption) SetKeyFile(path string) *ServerOption
SetKeyFile set KeyFile
func (*ServerOption) SetMaxHeaderBytes ¶
func (s *ServerOption) SetMaxHeaderBytes(n int) *ServerOption
SetMaxHeaderBytes set MaxHeaderBytes
func (*ServerOption) SetReadHeaderTimeout ¶
func (s *ServerOption) SetReadHeaderTimeout(t time.Duration) *ServerOption
SetReadHeaderTimeout set ReadHeaderTimeout
func (*ServerOption) SetReadTimeout ¶
func (s *ServerOption) SetReadTimeout(t time.Duration) *ServerOption
SetReadTimeout set ReadTimeout
func (*ServerOption) SetShutdownTimeout ¶
func (s *ServerOption) SetShutdownTimeout(t time.Duration) *ServerOption
SetShutdownTimeout set ShutdownTimeout
func (*ServerOption) SetWriteTimeout ¶
func (s *ServerOption) SetWriteTimeout(t time.Duration) *ServerOption
SetWriteTimeout set WriteTimeout