Documentation ¶
Overview ¶
Package httpserver httpserver统一封装,使API注册更容易
Index ¶
Constants ¶
View Source
const ( ContentTypeJSON = "application/json" ResponseWriter = "responseWriter" Base64EncodedRequestBody = "base64-encoded-request-body" TraceID = "dice-trace-id" )
Variables ¶
This section is empty.
Functions ¶
func WriteData ¶
func WriteData(w http.ResponseWriter, v interface{})
func WriteErr ¶
func WriteErr(w http.ResponseWriter, code, errMsg string)
func WriteJSON ¶
func WriteJSON(w http.ResponseWriter, v interface{})
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 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 apistructs.ErrorResponse `json:"err,omitempty"` UserIDs []string `json:"userIDs,omitempty"` }
Resp dice平台http body返回结构
type Responser ¶
type Responser interface { GetLocaledResp(locale *i18n.LocaleResource) HTTPResponse GetStatus() int GetContent() interface{} }
Responser is an interface for http response
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server provides ability to run a http server and handler registered URL paths.
func (*Server) ListenAndServe ¶
ListenAndServe boot the server to lisen and accept requests.
func (*Server) RegisterEndpoint ¶
RegisterEndpoint match URL path to corresponding handler
func (*Server) WithLocaleLoader ¶
func (s *Server) WithLocaleLoader(loader *i18n.LocaleResourceLoader)
WithLocaleLoader
Click to show internal directories.
Click to hide internal directories.