Documentation
¶
Index ¶
- Variables
- func BadRequest(w http.ResponseWriter, err string, code ...int)
- func ClientError(w http.ResponseWriter, err error, code ...int)
- func ErrAlreadyExists(k, v string) error
- func ErrInvalidKey(k string) error
- func ErrMissingKey(k string) error
- func ErrNotFound(k, v string) error
- func Forbidden(w http.ResponseWriter, err string)
- func IsMethodValid(method string) bool
- func IsStatusCodeValid(status int) bool
- func IsSuccess(status int) bool
- func JSONError(w http.ResponseWriter, err gperr.Error, code int)
- func LogDebug(r *http.Request) *zerolog.Event
- func LogError(r *http.Request) *zerolog.Event
- func LogInfo(r *http.Request) *zerolog.Event
- func LogWarn(r *http.Request) *zerolog.Event
- func NewTransport() *http.Transport
- func NewTransportWithTLSConfig(tlsConfig *tls.Config) *http.Transport
- func NotFound(w http.ResponseWriter, err string)
- func RespondJSON(w http.ResponseWriter, r *http.Request, data any, code ...int) (canProceed bool)
- func ServerError(w http.ResponseWriter, r *http.Request, err error, code ...int)
- func Unauthorized(w http.ResponseWriter, err string)
- func WriteBody(w http.ResponseWriter, body []byte)
- type AcceptContentType
- type ContentType
- type ModifyResponseFunc
- type ModifyResponseWriter
- func (w *ModifyResponseWriter) Flush()
- func (w *ModifyResponseWriter) Header() http.Header
- func (w *ModifyResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error)
- func (w *ModifyResponseWriter) Size() int
- func (w *ModifyResponseWriter) StatusCode() int
- func (w *ModifyResponseWriter) Unwrap() http.ResponseWriter
- func (w *ModifyResponseWriter) Write(b []byte) (int, error)
- func (w *ModifyResponseWriter) WriteHeader(code int)
- type ServeMux
Constants ¶
This section is empty.
Variables ¶
var ( Get = httpClient.Get Post = httpClient.Post Head = httpClient.Head )
var DefaultDialer = net.Dialer{ Timeout: 5 * time.Second, }
Functions ¶
func BadRequest ¶
func BadRequest(w http.ResponseWriter, err string, code ...int)
BadRequest returns a Bad Request response with the given error message.
func ClientError ¶
func ClientError(w http.ResponseWriter, err error, code ...int)
ClientError is for responding to client errors.
It returns http.StatusBadRequest with reason to the client. Status code can be specified as an argument.
For JSON marshallable errors (e.g. gperr.Error), it returns the error details as JSON. Otherwise, it returns the error details as plain text.
func ErrAlreadyExists ¶
func ErrInvalidKey ¶
func ErrMissingKey ¶
func ErrNotFound ¶
func Forbidden ¶
func Forbidden(w http.ResponseWriter, err string)
Forbidden returns a Forbidden response with the given error message.
func IsMethodValid ¶
func IsStatusCodeValid ¶
func JSONError ¶
func JSONError(w http.ResponseWriter, err gperr.Error, code int)
JSONError returns a JSON response of gperr.Error with the given status code.
func NewTransport ¶
func NotFound ¶
func NotFound(w http.ResponseWriter, err string)
NotFound returns a Not Found response with the given error message.
func RespondJSON ¶
func ServerError ¶
ServerError is for handling server errors.
It logs the error and returns http.StatusInternalServerError to the client. Status code can be specified as an argument.
func Unauthorized ¶
func Unauthorized(w http.ResponseWriter, err string)
Unauthorized returns an Unauthorized response with the given error message.
func WriteBody ¶
func WriteBody(w http.ResponseWriter, body []byte)
Types ¶
type AcceptContentType ¶
type AcceptContentType []ContentType
func GetAccept ¶
func GetAccept(h http.Header) AcceptContentType
func (AcceptContentType) AcceptHTML ¶
func (act AcceptContentType) AcceptHTML() bool
func (AcceptContentType) AcceptJSON ¶
func (act AcceptContentType) AcceptJSON() bool
func (AcceptContentType) AcceptPlainText ¶
func (act AcceptContentType) AcceptPlainText() bool
func (AcceptContentType) IsEmpty ¶
func (act AcceptContentType) IsEmpty() bool
type ContentType ¶
type ContentType string
func GetContentType ¶
func GetContentType(h http.Header) ContentType
func (ContentType) IsHTML ¶
func (ct ContentType) IsHTML() bool
func (ContentType) IsJSON ¶
func (ct ContentType) IsJSON() bool
func (ContentType) IsPlainText ¶
func (ct ContentType) IsPlainText() bool
type ModifyResponseFunc ¶
type ModifyResponseWriter ¶
type ModifyResponseWriter struct {
// contains filtered or unexported fields
}
func NewModifyResponseWriter ¶
func NewModifyResponseWriter(w http.ResponseWriter, r *http.Request, f ModifyResponseFunc) *ModifyResponseWriter
func (*ModifyResponseWriter) Flush ¶
func (w *ModifyResponseWriter) Flush()
Flush sends any buffered data to the client.
func (*ModifyResponseWriter) Header ¶
func (w *ModifyResponseWriter) Header() http.Header
func (*ModifyResponseWriter) Hijack ¶
func (w *ModifyResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error)
Hijack hijacks the connection.
func (*ModifyResponseWriter) Size ¶
func (w *ModifyResponseWriter) Size() int
func (*ModifyResponseWriter) StatusCode ¶
func (w *ModifyResponseWriter) StatusCode() int
func (*ModifyResponseWriter) Unwrap ¶
func (w *ModifyResponseWriter) Unwrap() http.ResponseWriter
func (*ModifyResponseWriter) WriteHeader ¶
func (w *ModifyResponseWriter) WriteHeader(code int)
type ServeMux ¶
func NewServeMux ¶
func NewServeMux() ServeMux
func (ServeMux) HandleFunc ¶
func (mux ServeMux) HandleFunc(pattern string, handler http.HandlerFunc) (err error)