Documentation ¶
Overview ¶
Package httpserver httpserver统一封装,使API注册更容易
Index ¶
- Constants
- func UnwrapI18nCodes(ctx context.Context) i18nProviders.LanguageCodes
- func WriteData(w http.ResponseWriter, v interface{}, userIDs ...string)
- 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
- func (s *Server) CheckDuplicateRoutes() ([]string, bool)
- func (s *Server) ListenAndServe() error
- func (s *Server) RegisterEndpoint(endpoints []Endpoint)
- func (s *Server) RegisterToNewHttpServerRouter(newRouter httpserver.Router) error
- func (s *Server) Router() *mux.Router
- func (s *Server) WithLocaleLoader(loader *i18n.LocaleResourceLoader)
- 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 UnwrapI18nCodes ¶
func UnwrapI18nCodes(ctx context.Context) i18nProviders.LanguageCodes
func WriteData ¶
func WriteData(w http.ResponseWriter, v interface{}, userIDs ...string)
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 ¶
func WithI18nCodes ¶
func Wrap ¶
func Wrap(h Handler, wrappers ...HandlerWrapper) Handler
type HandlerWrapper ¶
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 ¶
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server provides ability to run a http server and handler registered URL paths.
func NewSingleton ¶
func (*Server) CheckDuplicateRoutes ¶
CheckDuplicateRoutes return duplicate items and true if there is no duplicate.
func (*Server) ListenAndServe ¶
ListenAndServe boot the server to lisen and accept requests.
func (*Server) RegisterEndpoint ¶
RegisterEndpoint match URL path to corresponding handler
func (*Server) RegisterToNewHttpServerRouter ¶
func (s *Server) RegisterToNewHttpServerRouter(newRouter httpserver.Router) error
func (*Server) WithLocaleLoader ¶
func (s *Server) WithLocaleLoader(loader *i18n.LocaleResourceLoader)
WithLocaleLoader
Source Files ¶
Click to show internal directories.
Click to hide internal directories.