core

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type API

type API struct {
	MapMethods *MapMethods
	// contains filtered or unexported fields
}

API doc ...

func New

New doc ...

func (*API) AddMapMethod

func (api *API) AddMapMethod(key string, methods []string)

AddMapMethod doc ...

func (API) GetHeaderValueBool

func (api API) GetHeaderValueBool(key string, r *http.Request) (bool, error)

GetHeaderValueBool doc ...

func (API) GetHeaderValueFloat64

func (api API) GetHeaderValueFloat64(key string, r *http.Request) (float64, error)

GetHeaderValueFloat64 doc ...

func (API) GetHeaderValueInt

func (api API) GetHeaderValueInt(key string, r *http.Request) (int, error)

GetHeaderValueInt doc ...

func (API) GetHeaderValueInt64

func (api API) GetHeaderValueInt64(key string, r *http.Request) (int64, error)

GetHeaderValueInt64 doc ...

func (API) GetHeaderValueString

func (api API) GetHeaderValueString(key string, r *http.Request) (string, error)

GetHeaderValueString doc ...

func (API) GetQueryParamValueBool

func (api API) GetQueryParamValueBool(queryParamName string, r *http.Request) (bool, error)

GetQueryParamValueBool ...

func (API) GetQueryParamValueFloat64

func (api API) GetQueryParamValueFloat64(queryParamName string, r *http.Request) (float64, error)

GetQueryParamValueFloat64 ...

func (API) GetQueryParamValueInt

func (api API) GetQueryParamValueInt(queryParamName string, r *http.Request) (int, error)

GetQueryParamValueInt ...

func (API) GetQueryParamValueInt64

func (api API) GetQueryParamValueInt64(queryParamName string, r *http.Request) (int64, error)

GetQueryParamValueInt64 ...

func (API) GetQueryParamValueString

func (api API) GetQueryParamValueString(queryParamName string, r *http.Request) (string, error)

GetQueryParamValueString ...

func (API) GetRouteVarValueBool

func (api API) GetRouteVarValueBool(urlVarName string, r *http.Request) (bool, error)

GetRouteVarValueBool ...

func (API) GetRouteVarValueFloat64

func (api API) GetRouteVarValueFloat64(urlVarName string, r *http.Request) (float64, error)

GetRouteVarValueFloat64 ...

func (API) GetRouteVarValueInt

func (api API) GetRouteVarValueInt(urlVarName string, r *http.Request) (int, error)

GetRouteVarValueInt ...

func (API) GetRouteVarValueInt64

func (api API) GetRouteVarValueInt64(urlVarName string, r *http.Request) (int64, error)

GetRouteVarValueInt64 ...

func (API) GetRouteVarValueString

func (api API) GetRouteVarValueString(urlVarName string, r *http.Request) (string, error)

GetRouteVarValueString ...

func (*API) RegisterNewAPIRequestValidator

func (api *API) RegisterNewAPIRequestValidator(v APIRequestValidator)

RegisterNewAPIRequestValidator doc ...

func (*API) RegisterNewAPIResponseFormatter

func (api *API) RegisterNewAPIResponseFormatter(f APIResponseFormatter)

RegisterNewAPIResponseFormatter doc ...

func (*API) RegisterNewAPIResponseWriter

func (api *API) RegisterNewAPIResponseWriter(r APIResponseWriter)

RegisterNewAPIResponseWriter doc ...

func (*API) RegisterNewAPISecurity

func (api *API) RegisterNewAPISecurity(s APISecurity)

RegisterNewAPISecurity doc ...

func (API) UnmarshalBody

func (api API) UnmarshalBody(v interface{}, r *http.Request) error

UnmarshalBody doc ...

func (*API) ValidateBasicToken

func (api *API) ValidateBasicToken(token string) (client, secret string, valid bool)

ValidateBasicToken doc ...

func (*API) ValidateCustomToken

func (api *API) ValidateCustomToken(token string, customValidator CustomTokenValidator) (json.RawMessage, bool)

ValidateCustomToken doc ...

func (*API) ValidateMethods

func (api *API) ValidateMethods(keyMapMethod, method string) bool

ValidateMethods doc ...

func (*API) ValidateRequest

func (api *API) ValidateRequest(r *http.Request) (*RequestData, error)

ValidateRequest doc ...

func (*API) Write

func (api *API) Write(data ResponseData, w http.ResponseWriter)

Write doc ...

type APIRequestValidator

type APIRequestValidator interface {
	ValidateRequest(*http.Request) (*RequestData, error)
	// GetRouteVar returns the route var for the current request, if any.
	GetRouteVar(string, *http.Request) string
}

APIRequestValidator doc ...

type APIResponseFormatter

type APIResponseFormatter interface {
	Format(ResponseData) *ResponseFormatted
}

APIResponseFormatter doc ...

type APIResponseWriter

type APIResponseWriter interface {
	Write(*ResponseFormatted, http.ResponseWriter)
}

APIResponseWriter doc ...

type APISecurity

type APISecurity interface {
	ValidateBasicToken(token string) (client, secret string, valid bool)
	ValidateCustomToken(token string, validator CustomTokenValidator) (json.RawMessage, bool)
}

APISecurity doc ...

type CustomTokenValidator

type CustomTokenValidator func(string) (json.RawMessage, bool)

CustomTokenValidator validator custom token func

type MapMethods

type MapMethods map[string][]string

MapMethods doc ...

type Middleware

type Middleware func(next http.HandlerFunc) http.HandlerFunc

Middleware provides a convenient mechanism for filtering HTTP requests entering the application. It returns a new handler which may perform various operations and should finish by calling the next HTTP handler.

func MiddlewaresChain

func MiddlewaresChain(mw ...Middleware) Middleware

MiddlewaresChain provides syntactic sugar to create a new middleware which will be the result of chaining the ones received as parameters.

type RequestData

type RequestData struct {
	UUID            string
	DeviceType      string
	DeviceBrand     string
	DeviceModel     string
	OS              string
	OSVersion       string
	Lang            string
	Timezone        string
	AppVersion      string
	AppBuildVersion string
	AppName         string
	Token           string
	Headers         map[string]string
	AdditionalInfo  map[string]string
	RawBody         []byte
	Data            interface{}
}

RequestData doc ..

func (*RequestData) AddAdditionalInfo

func (data *RequestData) AddAdditionalInfo(key, value string)

AddAdditionalInfo func ...

func (*RequestData) AddHeader

func (data *RequestData) AddHeader(key, value string)

AddHeader doc

type ResponseData

type ResponseData struct {
	Title          string
	Message        string
	StatusCode     int
	Code           string
	Action         string
	Token          string
	EventID        string
	ResponseType   ResponseType
	Headers        map[string]string
	AdditionalInfo map[string]string
	Data           interface{}
}

ResponseData doc ..

func (*ResponseData) AddAdditionalInfo

func (data *ResponseData) AddAdditionalInfo(key, value string)

AddAdditionalInfo func ...

func (*ResponseData) AddHeader

func (data *ResponseData) AddHeader(key, value string)

AddHeader doc

type ResponseFormatted

type ResponseFormatted struct {
	Headers    map[string]string
	StatusCode int
	Data       interface{}
}

ResponseFormatted ...

type ResponseType

type ResponseType string

ResponseType contains all the response types identifers

Jump to

Keyboard shortcuts

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