Documentation ¶
Overview ¶
Package httpserver httpserver统一封装,使API注册更容易
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 Endpoint
- type HTTPResponse
- type Handler
- type HandlerWrapper
- type Resp
- type Responser
- type ReverseHandler
- type Server
- type WriterHandler
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 Handler WriterHandler WriterHandler ReverseHandler ReverseHandler }
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 Handler ¶ added in v1.5.0
func WithI18nCodes ¶ added in v1.5.0
func Wrap ¶ added in v1.5.0
func Wrap(h Handler, wrappers ...HandlerWrapper) Handler
type HandlerWrapper ¶ added in v1.5.0
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 ReverseHandler ¶ added in v1.5.0
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.