Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddHTTPServerSubscriber ¶
func AddHTTPServerSubscriber(subscriber HTTPServerSubscriber)
AddHTTPServerSubscriber register callback to HTTP server
func OnHTTPServerInit ¶
func OnHTTPServerInit(ctx context.Context, engine *gin.Engine, data *common.TranslatorData, httpService *HTTPService)
OnHTTPServerInit call all registered callbacks on HTTP server initialization
func RespondWithError ¶
RespondWithError encode error to proper response format and write to client using ctx
Types ¶
type HTTPError ¶
type HTTPError struct { Code int `json:"code" example:"400"` Message string `json:"message" example:"invalid request body"` }
HTTPError store HTTP response status and message
func NewHTTPError ¶
NewHTTPError return new initialized HTTPError
type HTTPServerSubscriber ¶
type HTTPServerSubscriber interface {
OnHTTPServerInit(ctx context.Context, engine *gin.Engine, data *common.TranslatorData, httpService *HTTPService)
}
HTTPServerSubscriber interface declares callbacks raised by HTTP server
type HTTPService ¶
type HTTPService struct {
// contains filtered or unexported fields
}
HTTPService implements HTTP API v1 and REST API v2 using ITranslatorService as logic backend
func NewHTTPService ¶
func NewHTTPService(service common.ITranslatorService, translatorData *common.TranslatorData, options ...ServiceOption) (*HTTPService, error)
NewHTTPService return new initialized http service that ready to process new connections
type ServiceOption ¶
type ServiceOption func(service *HTTPService)
ServiceOption to configure HTTPService
func WithConnectionContextHandler ¶
func WithConnectionContextHandler(handler func(ctx context.Context, c net.Conn) context.Context) ServiceOption
WithConnectionContextHandler return new option that registers http.Server.ConnContext handler for http.Server
func WithContext ¶
func WithContext(ctx context.Context) ServiceOption
WithContext return option that configures HTTPService with specified context