Documentation
¶
Index ¶
- Constants
- Variables
- func BadRequest(ctx context.Context, msg string, err error) error
- func Bind(ctx context.Context, r *http.Request, v interface{}) error
- func Client() *http.Client
- func Created(ctx context.Context, w http.ResponseWriter, val interface{})
- func ElementIntoHeader(ctx context.Context, header http.Header, key log.ContextField) http.Header
- func Error(ctx context.Context, w http.ResponseWriter, err error)
- func Forbidden(ctx context.Context, err error) error
- func FromHeader(ctx context.Context, header http.Header, ...) context.Context
- func Generic(ctx context.Context, w http.ResponseWriter, val interface{}, statusCode int)
- func GetCorrelationID(ctx context.Context) string
- func GetQueryStringParam(query url.Values, param string) null.String
- func GetQueryTimeParam(query url.Values, param, format string) null.Time
- func GetQueryUint64Param(query url.Values, param string) null.Uint64
- func GetValues(ctx context.Context, contextKeys map[string]log.ContextField) map[interface{}]interface{}
- func Hello(w http.ResponseWriter, r *http.Request)
- func InternalServerError(ctx context.Context, err error) error
- func IntoHeader(ctx context.Context, header http.Header, ...) http.Header
- func Livez(w http.ResponseWriter, r *http.Request)
- func NoContent(ctx context.Context, w http.ResponseWriter)
- func NotFound(ctx context.Context, msg string, err error) error
- func NotReady()
- func Ready()
- func Readyz(w http.ResponseWriter, r *http.Request)
- func ReadyzWithChecks(checks ...func(ctx context.Context) error) func(w http.ResponseWriter, r *http.Request)
- func Request(ctx context.Context, respStruct interface{}, opts RequestOpts) (*http.Response, error)
- func ReturnBadRequest(ctx context.Context, w http.ResponseWriter, msg string, err error)
- func ReturnForbidden(ctx context.Context, w http.ResponseWriter, err error)
- func ReturnInternalServerError(ctx context.Context, w http.ResponseWriter, err error)
- func ReturnNotFound(ctx context.Context, w http.ResponseWriter, msg string, err error)
- func ReturnUnauthorized(ctx context.Context, w http.ResponseWriter, err error)
- func ServiceLive(ctx context.Context, url string) error
- func ServiceReady(ctx context.Context, url string) error
- func SetClientMaxConnsPerHost(v int)
- func SetClientMaxIdleConns(v int)
- func SetClientMaxIdleConnsPerHost(v int)
- func SetClientTimeout(v time.Duration)
- func SetJSONEncoder(e JSONEncoder)
- func SilentProxy(ctx context.Context, w http.ResponseWriter, resp *http.Response)
- func StatusHandler(opts StatusOpts) func(w http.ResponseWriter, r *http.Request)
- func Success(ctx context.Context, w http.ResponseWriter, val interface{})
- func SuccessDownload(ctx context.Context, w http.ResponseWriter, res []byte)
- func Unauthorized(ctx context.Context, err error) error
- type EnvironmentTLSOpts
- type FileTLSOpts
- type HTTP
- type JSONEncoder
- type Logger
- type MockReadCloser
- type RequestOpts
- type StatusFn
- type StatusOpts
- type TLSDescriptor
- type Wrapper
- type Writer
Constants ¶
const ( StatusAsLibrary = "lib" StatusAsService = "svc" )
const HeaderPrefix = "Ctx_"
Variables ¶
var ( ErrBindMissingBody = errors.New("request bind error, missing request body") ErrBind = "request bind error, " )
var ( MissingRequestBody = "Missing request body" InvalidRequest = "Invalid request" )
var ErrMissingHandler = errors.New("missing http.Handler, pass it in the HTTP struct")
Functions ¶
func Created ¶
func Created(ctx context.Context, w http.ResponseWriter, val interface{})
Created build a success response with HTTP Status Created
func ElementIntoHeader ¶
func Error ¶
func Error(ctx context.Context, w http.ResponseWriter, err error)
Error build an error response, the HTTP status will get from the error, default 500
func FromHeader ¶
func Generic ¶
func Generic(ctx context.Context, w http.ResponseWriter, val interface{}, statusCode int)
Generic build a generic response
func GetCorrelationID ¶
func GetQueryStringParam ¶
GetQueryStringParam getting a query param if exist or return with null.String{Valid: false}
func GetQueryTimeParam ¶ added in v0.3.0
GetQueryTimeParam getting a query param if exist or return with null.Time{Valid: false}
func GetQueryUint64Param ¶
GetQueryUint64Param getting a query param if exist or return with null.Uint64{Valid: false}
func GetValues ¶
func GetValues(ctx context.Context, contextKeys map[string]log.ContextField) map[interface{}]interface{}
func Hello ¶
func Hello(w http.ResponseWriter, r *http.Request)
Hello returns http.StatusOk and the Hello response
func IntoHeader ¶
func Livez ¶
func Livez(w http.ResponseWriter, r *http.Request)
Livez returns http.StatusOk when the service does not need to be killed
func NoContent ¶
func NoContent(ctx context.Context, w http.ResponseWriter)
NoContent build a no content success response
func Readyz ¶
func Readyz(w http.ResponseWriter, r *http.Request)
Readyz returns http.StatusOk when the service is ready accept connections, otherwise Http.StatusServiceUnavailable
func ReadyzWithChecks ¶ added in v0.3.4
func ReturnBadRequest ¶
func ReturnForbidden ¶
func ReturnForbidden(ctx context.Context, w http.ResponseWriter, err error)
func ReturnInternalServerError ¶
func ReturnInternalServerError(ctx context.Context, w http.ResponseWriter, err error)
func ReturnNotFound ¶
func ReturnUnauthorized ¶
func ReturnUnauthorized(ctx context.Context, w http.ResponseWriter, err error)
func SetClientMaxConnsPerHost ¶
func SetClientMaxConnsPerHost(v int)
func SetClientMaxIdleConns ¶
func SetClientMaxIdleConns(v int)
func SetClientMaxIdleConnsPerHost ¶
func SetClientMaxIdleConnsPerHost(v int)
func SetClientTimeout ¶
func SetJSONEncoder ¶ added in v0.4.0
func SetJSONEncoder(e JSONEncoder)
func SilentProxy ¶
func StatusHandler ¶
func StatusHandler(opts StatusOpts) func(w http.ResponseWriter, r *http.Request)
func Success ¶
func Success(ctx context.Context, w http.ResponseWriter, val interface{})
Success build a success response with HTTP Status OK
func SuccessDownload ¶
func SuccessDownload(ctx context.Context, w http.ResponseWriter, res []byte)
SuccessDownload build a success response with content type octet/stream
Types ¶
type EnvironmentTLSOpts ¶
type FileTLSOpts ¶
type HTTP ¶
type JSONEncoder ¶ added in v0.4.0
type MockReadCloser ¶
MockReadCloser implements the io.ReadCloser interface Mocks the request.Body
func NewMockReadCloser ¶
func NewMockReadCloser(ctx context.Context, data interface{}) MockReadCloser
func (MockReadCloser) Close ¶
func (cb MockReadCloser) Close() (err error)
type RequestOpts ¶
type StatusOpts ¶
type TLSDescriptor ¶
type TLSDescriptor interface {
// contains filtered or unexported methods
}
func NewEnvironmentTLS ¶
func NewEnvironmentTLS(e EnvironmentTLSOpts) TLSDescriptor
func NewFileTLS ¶
func NewFileTLS(e FileTLSOpts) TLSDescriptor
type Wrapper ¶
type Wrapper struct { // TokenJWT returns a new JWT token, if it filled that means the frontend should change it // NOTE: temporary it's hidden, because we use cookies TokenJWT string `json:"-"` // UserJWT returns a new JWT with user info, if it filled that means the frontend should change it // NOTE: temporary it's hidden, because we use cookies UserJWT string `json:"-"` // Error Error string `json:"error,omitempty"` // Data is the exact data of the response Data interface{} `json:"data,omitempty"` }
Wrapper wraps the response
type Writer ¶
type Writer struct { W http.ResponseWriter StatusCode int // contains filtered or unexported fields }
Writer also implements the http.ResponseWriter interface In the future we may add other fields as well.
func (*Writer) ResponseBody ¶
func (*Writer) Write ¶
Write writes the data to the connection as part of an HTTP reply, and stores the response data for logging purpose
func (*Writer) WriteHeader ¶
WriteHeader 'overrides' the http.ResponseWriter's WriteHeader method