webapi

package
v0.0.0-...-c8a7627 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2022 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const AuthHeaderParts = 2

Variables

This section is empty.

Functions

func BadRequest

func BadRequest(ctx context.Context, w http.ResponseWriter, msg string)

func CreateRouter

func CreateRouter(params *RouterParams) *chi.Mux

func CreatedResponse

func CreatedResponse(ctx context.Context, w http.ResponseWriter, data any)

func Forbidden

func Forbidden(ctx context.Context, w http.ResponseWriter, msg string)

func InternalServerError

func InternalServerError(ctx context.Context, w http.ResponseWriter, msg string)

func NewCompanyID

func NewCompanyID() uuid.UUID

func NewCreatedAt

func NewCreatedAt() time.Time

func NotFound

func NotFound(ctx context.Context, w http.ResponseWriter, msg string)

func OKResponse

func OKResponse(ctx context.Context, w http.ResponseWriter, data any)

func Unauthorized

func Unauthorized(ctx context.Context, w http.ResponseWriter, msg string)

func WithAuthN

func WithAuthN(tokenService authn.TokenValidator) func(next http.Handler) http.Handler

func WithCountryRestriction

func WithCountryRestriction(
	geoIPService geoip.CountryDetector, allowedCountryName string,
) func(next http.Handler) http.Handler

func WithLogRequestBoundaries

func WithLogRequestBoundaries() func(next http.Handler) http.Handler

func WithXRequestID

func WithXRequestID(next http.Handler) http.Handler

Types

type CompaniesSearchRequest

type CompaniesSearchRequest struct {
	CompaniesIDs []string `json:"companies_ids"` //nolint:tagliatelle // false positive
}

type CompaniesSearchResponse

type CompaniesSearchResponse []CompanyResponse

type CompanyResponse

type CompanyResponse struct {
	CreatedAt time.Time `json:"created_at"`
	InputCompany
	ID uuid.UUID `json:"id"`
}

type GetCompanyResponse

type GetCompanyResponse struct {
	CompanyResponse
}

type HandlerEnv

type HandlerEnv struct {
	DbConn *sqlx.DB
}

func (*HandlerEnv) DeleteCompany

func (h *HandlerEnv) DeleteCompany(w http.ResponseWriter, r *http.Request)

func (*HandlerEnv) GetCompany

func (h *HandlerEnv) GetCompany(w http.ResponseWriter, r *http.Request)

func (*HandlerEnv) PostCompanies

func (h *HandlerEnv) PostCompanies(w http.ResponseWriter, r *http.Request)

func (*HandlerEnv) PostCompaniesSearch

func (h *HandlerEnv) PostCompaniesSearch(w http.ResponseWriter, r *http.Request)

PostCompaniesSearch is used to fetch list of companies POST was chosen instead GET we can pass parameters only in URL, but URL max length is 2048, so we will pass parameters in body in POST request.

type InputCompany

type InputCompany struct {
	Name    string `json:"name"`
	Code    string `json:"code"`
	Country string `json:"country"`
	WebSite string `json:"website"` //nolint:tagliatelle // need to discuss
	Phone   string `json:"phone"`
}

type PostCompanyResponse

type PostCompanyResponse struct {
	CompanyResponse
}

type Response

type Response struct {
	HTTPBody   *ResponseBody
	HTTPStatus int
}

type ResponseBody

type ResponseBody struct {
	Data  any    `json:"data,omitempty"`
	Error string `json:"error,omitempty"`
}

type RouterParams

type RouterParams struct {
	Logger          logging.Logger
	Handler         *HandlerEnv
	CountryDetector geoip.CountryDetector
	GeoIPConf       *config.GeoIP
	TokenService    authn.TokenValidator
}

Jump to

Keyboard shortcuts

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