common

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2021 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Prefix                   = "internal.dispatcher"
	UnmarshalKey             = "dispatcher"
	UnmarshalGlobalConfigKey = "dispatcher.global"
	NoAuthGroupPath          = "/api/v1"
)
View Source
const (
	RequestParameterId        = "id"
	RequestParameterOrderId   = "order_id"
	RequestParameterZipUsa    = "zip_usa"
	RequestParameterReceiptId = "receipt_id"

	QueryParameterNameUtmMedium   = "utm_medium"
	QueryParameterNameUtmCampaign = "utm_campaign"
	QueryParameterNameUtmSource   = "utm_source"

	ErrorMessageMask = "field validation for '%s' failed on the '%s' tag"

	HeaderAcceptLanguage      = "Accept-Language"
	HeaderUserAgent           = "User-Agent"
	HeaderXApiSignatureHeader = "X-API-SIGNATURE"
	HeaderReferer             = "referer"

	ErrorFieldService = "service"
	ErrorFieldMethod  = "method"
	ErrorFieldRequest = "request"

	InternalErrorTemplate = "internal error"

	ValidationParameterOrderId   = "OrderId"
	ValidationParameterOrderUuid = "OrderUuid"
)

Variables

View Source
var (
	BinderDefault     = &Binder{}
	EchoBinderDefault = &echo.DefaultBinder{}
)
View Source
var (
	ErrorUnknown                       = NewManagementApiResponseError("co000001", "unknown error. try request later")
	ErrorValidationFailed              = NewManagementApiResponseError("co000002", "validation failed")
	ErrorInternal                      = NewManagementApiResponseError("co000003", InternalErrorTemplate)
	ErrorIncorrectOrderId              = NewManagementApiResponseError("co000004", "incorrect order identifier")
	ErrorMessageSignatureHeaderIsEmpty = NewManagementApiResponseError("co000005", "header with request signature can't be empty")
	ErrorRequestParamsIncorrect        = NewManagementApiResponseError("co000006", "incorrect request parameters")
	ErrorRequestDataInvalid            = NewManagementApiResponseError("co000007", "request data invalid")
	ErrorMessageIncorrectZip           = NewManagementApiResponseError("co000008", "incorrect zip code")

	ValidationErrors = map[string]billingpb.ResponseErrorMessage{
		ValidationParameterOrderId:   ErrorIncorrectOrderId,
		ValidationParameterOrderUuid: ErrorIncorrectOrderId,
	}
)
View Source
var FuncMap = template.FuncMap{
	"Marshal": func(v interface{}) template.JS {
		a, _ := json.Marshal(v)
		return template.JS(a)
	},
}

Functions

func CheckProjectAuthRequestSignature

func CheckProjectAuthRequestSignature(dispatch HandlerSet, ctx echo.Context, projectId string) error

CheckProjectAuthRequestSignature

func ExtractBinderContext

func ExtractBinderContext(ctx echo.Context) echo.Binder

ExtractBinderContext

func ExtractRawBodyContext

func ExtractRawBodyContext(ctx echo.Context) []byte

ExtractRawBodyContext

func GetValidationError

func GetValidationError(err error) (rspErr billingpb.ResponseErrorMessage)

GetValidationError

func LogSrvCallFailedGRPC

func LogSrvCallFailedGRPC(log logger.Logger, err error, name, method string, req interface{})

func NewManagementApiResponseError

func NewManagementApiResponseError(code, msg string, details ...string) billingpb.ResponseErrorMessage

NewManagementApiResponseError

func NewValidationError

func NewValidationError(details string) billingpb.ResponseErrorMessage

NewValidationError

func RequestResponseHeadersToString

func RequestResponseHeadersToString(headers map[string][]string) string

RequestResponseHeadersToString

func SetBinder

func SetBinder(ctx echo.Context, binder echo.Binder)

SetBinder

func SetRawBodyContext

func SetRawBodyContext(ctx echo.Context, rawBody []byte)

SetRawBodyContext

Types

type Binder

type Binder struct{}

func (*Binder) Bind

func (b *Binder) Bind(i interface{}, ctx echo.Context) (err error)

type Config

type Config struct {
	CookieDomain string `envconfig:"COOKIE_DOMAIN" required:"true"`
	CookieName   string `envconfig:"COOKIE_NAME" default:"_ps_ctkn"`
	AllowOrigin  string `envconfig:"ALLOW_ORIGIN" default:"*"`

	// OrderInlineFormUrlMask url like a https://checkout.tst.pay.super.com/pay/order/
	OrderInlineFormUrlMask string `envconfig:"ORDER_INLINE_FORM_URL_MASK" required:"true"`

	CustomerTokenCookiesLifetimeHours int64 `envconfig:"CUSTOMER_TOKEN_COOKIES_LIFETIME" default:"720"`
}

type Dictionary

type Dictionary struct {
	Key   string `json:"key"`
	Value string `json:"value"`
}

type Groups

type Groups struct {
	Common *echo.Group
}

Groups

type Handler

type Handler interface {
	Route(groups *Groups)
}

Handler

type HandlerSet

type HandlerSet struct {
	Services Services
	Validate *validator.Validate
	AwareSet provider.AwareSet
}

HandlerSet

func (HandlerSet) BindAndValidate

func (h HandlerSet) BindAndValidate(req interface{}, ctx echo.Context) *echo.HTTPError

BindAndValidate

func (HandlerSet) SrvCallHandler

func (h HandlerSet) SrvCallHandler(req interface{}, err error, name, method string) *echo.HTTPError

SrvCallHandler returns error if present, otherwise response as JSON with 200 OK

type Handlers

type Handlers []Handler

Handlers

type OrderJsonBinder

type OrderJsonBinder struct{}

func (*OrderJsonBinder) Bind

func (cb *OrderJsonBinder) Bind(i interface{}, ctx echo.Context) (err error)

Bind

type PaymentCreateProcessBinder

type PaymentCreateProcessBinder struct{}

func (*PaymentCreateProcessBinder) Bind

func (cb *PaymentCreateProcessBinder) Bind(i interface{}, ctx echo.Context) (err error)

Bind

type Services

type Services struct {
	Billing billingpb.BillingService
}

Services

type Template

type Template struct {
	// contains filtered or unexported fields
}

Template

func NewTemplate

func NewTemplate(tpl *template.Template) *Template

NewTemplate

func (*Template) Render

func (t *Template) Render(w io.Writer, name string, data interface{}, c echo.Context) error

Render

type Validator

type Validator interface {
	Use(validator *validator.Validate)
}

Validate

Jump to

Keyboard shortcuts

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