http_api

package
v0.0.0-...-982e07a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 19, 2023 License: Apache-2.0 Imports: 23 Imported by: 0

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

func RespondWithError(ctx *gin.Context, err HTTPError)

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

func NewHTTPError(status int, message string) HTTPError

NewHTTPError return new initialized HTTPError

func (HTTPError) Empty

func (err HTTPError) Empty() bool

Empty return true if Code and Message equal to init values

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

func (*HTTPService) Start

func (service *HTTPService) Start(listener net.Listener) error

Start http server that process new HTTP connections through listener

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL