Documentation ¶
Index ¶
- func CreatePageToken(arrayData interface{}, dataLimit int, fieldNameId string, fieldNameDate string) (nextToken string)
- func New(w io.Writer, lvl zerolog.Level, withTimestamp bool) zerolog.Logger
- func NewHttpHandler(c HttpHandlerContext, opts ...HandlerOption) func(...) PerkakasHttpHandler
- func ParsePageToken(pageToken string) (token map[string]string)
- type APIResponse
- type BaseResponse
- type CustomSuccessResp
- type CustomWriter
- type ErrResD
- type ErrResponse
- type HandlerOption
- type HttpHandlerContext
- type Meta
- type PerkakasHttpHandler
- type ResponseDesc
- type ServiceError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreatePageToken ¶
func NewHttpHandler ¶
func NewHttpHandler(c HttpHandlerContext, opts ...HandlerOption) func(handler func(w http.ResponseWriter, r *http.Request) (interface{}, *string, error)) PerkakasHttpHandler
func ParsePageToken ¶
Types ¶
type APIResponse ¶
type APIResponse struct { *BaseResponse Meta Meta `json:"meta"` Next *string `json:"next,omitempty"` //deprecated in v3. Will be removed Pagination *paginationPkg.Pagination `json:"pagination,omitempty"` Data interface{} `json:"data,omitempty"` *ErrResponse // contains filtered or unexported fields }
type BaseResponse ¶
type BaseResponse struct { ResponseCode string `json:"response_code,omitempty"` ResponseMessage string `json:"response_message,omitempty"` ResponseDesc *ResponseDesc `json:"response_desc,omitempty"` //deprecated in v3. Will be removed }
type CustomSuccessResp ¶
type CustomSuccessResp struct { ResponseCode string ResponseMessage string StatusCode int Header map[string]string Pagination *paginationPkg.Pagination }
type CustomWriter ¶
type CustomWriter struct {
C HttpHandlerContext
}
func (*CustomWriter) Write ¶
func (c *CustomWriter) Write(ctx context.Context, w http.ResponseWriter, data interface{}, nextPage *string)
func (*CustomWriter) WriteError ¶
func (c *CustomWriter) WriteError(ctx context.Context, w http.ResponseWriter, err error)
WriteError sending error response based on err type
type ErrResD ¶
type ErrResD struct {
APIResponse
}
func (*ErrResD) HTTPErrorResponse ¶
HTTPErrorResponse takes a writer, error and a logger, performs a type switch to determine if the type is an Error (which meets the Error interface as defined in this package), then sends the Error as a response to the client. If the type does not meet the Error interface as defined in this package, then a proper error is still formed and sent to the client, however, the Kind and Code will be Unexpected. Logging of error is also done using https://github.com/rs/zerolog
type ErrResponse ¶
type ErrResponse struct {
Error ServiceError `json:"error,omitempty"`
}
ErrResponse is used as the Response Body
type HandlerOption ¶
type HandlerOption func(*PerkakasHttpHandler)
type HttpHandlerContext ¶
type HttpHandlerContext struct { M Meta CustomSuccessResponse *CustomSuccessResp }
func NewContextHandler ¶
func NewContextHandler(meta Meta) HttpHandlerContext
NewContextHandler add base error response
type Meta ¶
type Meta struct { Version string `json:"version" mapstructure:"version"` Status string `json:"api_status" mapstructure:"api_status"` APIEnv string `json:"api_env" mapstructure:"api_env"` RequestId string `json:"request_id,omitempty"` }
Meta defines meta format format for api format
type PerkakasHttpHandler ¶
type PerkakasHttpHandler struct { // H is handler, with return interface{} as data object, *string for token next page, error for error type H func(w http.ResponseWriter, r *http.Request) (interface{}, *string, error) CustomWriter Metric *statsd.Client ServiceName string }
func (PerkakasHttpHandler) ServeHTTP ¶
func (h PerkakasHttpHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
type ResponseDesc ¶
ResponseDesc defines details data response