Documentation ¶
Index ¶
- Constants
- func WriteData(w http.ResponseWriter, v interface{})
- func WriteErr(w http.ResponseWriter, code, errMsg string)
- func WriteJSON(w http.ResponseWriter, v interface{})
- func WriteYAML(w http.ResponseWriter, v string)
- type ContextKey
- type Endpoint
- type ErrorResponse
- type HTTPResponse
- type Interface
- type Resp
- type Responser
Constants ¶
View Source
const ( // ContentTypeJSON Content Type ContentTypeJSON = "application/json" // ResponseWriter context value key ResponseWriter = ContextKey("responseWriter") // Base64EncodedRequestBody . Base64EncodedRequestBody = "base64-encoded-request-body" // TraceID . TraceID = ContextKey("dice-trace-id") )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Endpoint ¶
type Endpoint struct { Path string Method string Handler func(context.Context, *http.Request, map[string]string) (Responser, error) WriterHandler func(context.Context, http.ResponseWriter, *http.Request, map[string]string) error ReverseHandler func(context.Context, *http.Request, map[string]string) error }
Endpoint contains URL path and corresponding handler
type ErrorResponse ¶
type ErrorResponse struct { Code string `json:"code"` Msg string `json:"msg"` Ctx interface{} `json:"ctx"` }
ErrorResponse .
type HTTPResponse ¶
HTTPResponse is a struct contains status code and content body
func (HTTPResponse) GetContent ¶
func (r HTTPResponse) GetContent() interface{}
GetContent returns http content body
func (HTTPResponse) GetLocaledResp ¶
func (r HTTPResponse) GetLocaledResp(locale i18n.LocaleResource) HTTPResponse
GetLocaledResp .
func (HTTPResponse) GetStatus ¶
func (r HTTPResponse) GetStatus() int
GetStatus returns http status code.
type Resp ¶
type Resp struct { Success bool `json:"success"` Data interface{} `json:"data,omitempty"` Err ErrorResponse `json:"err,omitempty"` UserIDs []string `json:"userIDs,omitempty"` }
Resp .
type Responser ¶
type Responser interface { GetLocaledResp(locale i18n.LocaleResource) HTTPResponse GetStatus() int GetContent() interface{} }
Responser is an interface for http response
Click to show internal directories.
Click to hide internal directories.