Documentation
¶
Index ¶
- type API
- func (api *API) AddMapMethod(key string, methods []string)
- func (api API) GetHeaderValueBool(key string, r *http.Request) (bool, error)
- func (api API) GetHeaderValueFloat64(key string, r *http.Request) (float64, error)
- func (api API) GetHeaderValueInt(key string, r *http.Request) (int, error)
- func (api API) GetHeaderValueInt64(key string, r *http.Request) (int64, error)
- func (api API) GetHeaderValueString(key string, r *http.Request) (string, error)
- func (api API) GetQueryParamValueBool(queryParamName string, r *http.Request) (bool, error)
- func (api API) GetQueryParamValueFloat64(queryParamName string, r *http.Request) (float64, error)
- func (api API) GetQueryParamValueInt(queryParamName string, r *http.Request) (int, error)
- func (api API) GetQueryParamValueInt64(queryParamName string, r *http.Request) (int64, error)
- func (api API) GetQueryParamValueString(queryParamName string, r *http.Request) (string, error)
- func (api API) GetRouteVarValueBool(urlVarName string, r *http.Request) (bool, error)
- func (api API) GetRouteVarValueFloat64(urlVarName string, r *http.Request) (float64, error)
- func (api API) GetRouteVarValueInt(urlVarName string, r *http.Request) (int, error)
- func (api API) GetRouteVarValueInt64(urlVarName string, r *http.Request) (int64, error)
- func (api API) GetRouteVarValueString(urlVarName string, r *http.Request) (string, error)
- func (api *API) ProcessBody(r *http.Request) (*RequestDataContext, error)
- func (api *API) ProcessEncryptedBody(r *http.Request) (*RequestEncryptedData, error)
- func (api *API) RegisterNewAPIRequestReceiver(receiver APIRequestReceiver)
- func (api *API) RegisterNewAPIResponseFormatter(formatter APIResponseFormatter)
- func (api *API) RegisterNewAPIResponseWriter(writer APIResponseWriter)
- func (api *API) RegisterNewAPISecurityGuarantor(guarantor APISecurityGuarantor)
- func (api *API) RegisterParamValidator(paramValidator func(any) (errMsg string, err error))
- func (api API) UnmarshalBody(v interface{}, r *http.Request) error
- func (api *API) ValidateBasicToken(token string) (client, secret string, valid bool)
- func (api *API) ValidateCustomToken(token string, customValidator CustomTokenValidator) (json.RawMessage, bool)
- func (api *API) ValidateMethods(keyMapMethod, method string) bool
- func (api API) ValidateParams(v any) (errMsg string, err error)
- func (api *API) Write(data ResponseData, w http.ResponseWriter)
- type APIRequestReceiver
- type APIResponseFormatter
- type APIResponseWriter
- type APISecurityGuarantor
- type CustomTokenValidator
- type JSONContent
- type MapMethods
- type Middleware
- type ParamValidator
- type RequestDataContext
- func (data *RequestDataContext) AddHeader(key, value string)
- func (data *RequestDataContext) AddInfo(key, value string)
- func (data *RequestDataContext) DecodeContent(v interface{}) error
- func (data *RequestDataContext) Get(key string) (value interface{})
- func (data *RequestDataContext) GetBool(key string) bool
- func (data *RequestDataContext) GetFloat(key string) float64
- func (data *RequestDataContext) GetInt(key string) int
- func (data *RequestDataContext) GetInt64(key string) int64
- func (data *RequestDataContext) GetString(key string) string
- func (data *RequestDataContext) GetStruct(key string, v interface{}) error
- func (data *RequestDataContext) Set(key string, value interface{})
- type RequestEncryptedData
- type ResponseCode
- type ResponseData
- type ResponseFormatted
- type ResponseType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type API ¶
type API struct {
// MapMethods contain a array of HTTP methos for API validations.
MapMethods *MapMethods
// contains filtered or unexported fields
}
API core developer toolkit.
func New ¶
func New(receiver APIRequestReceiver, formater APIResponseFormatter, writer APIResponseWriter, guarantor APISecurityGuarantor, mapMethods *MapMethods, paramValidator ParamValidator) *API
New API core developer toolkit.
func (*API) AddMapMethod ¶
AddMapMethod add a new method in a map of methods.
func (API) GetHeaderValueBool ¶
GetHeaderValueBool gets header values as bool.
func (API) GetHeaderValueFloat64 ¶
GetHeaderValueFloat64 gets header value as float 64.
func (API) GetHeaderValueInt ¶
GetHeaderValueInt gets header value as integer.
func (API) GetHeaderValueInt64 ¶
GetHeaderValueInt64 gets header value as integer 64.
func (API) GetHeaderValueString ¶
GetHeaderValueString gets header value as string.
func (API) GetQueryParamValueBool ¶
GetQueryParamValueBool gets param value as bool.
func (API) GetQueryParamValueFloat64 ¶
GetQueryParamValueFloat64 gets query param value as float 64.
func (API) GetQueryParamValueInt ¶
GetQueryParamValueInt gets query param value as integer.
func (API) GetQueryParamValueInt64 ¶
GetQueryParamValueInt64 gets query param value as integer 64.
func (API) GetQueryParamValueString ¶
GetQueryParamValueString gets query param value as string.
func (API) GetRouteVarValueBool ¶
GetRouteVarValueBool gets route variable value as bool.
func (API) GetRouteVarValueFloat64 ¶
GetRouteVarValueFloat64 gets route variable value as float 64.
func (API) GetRouteVarValueInt ¶
GetRouteVarValueInt gets route variable value as integer.
func (API) GetRouteVarValueInt64 ¶
GetRouteVarValueInt64 gets route variable value as integer 64.
func (API) GetRouteVarValueString ¶
GetRouteVarValueString gets route variable value as string.
func (*API) ProcessBody ¶ added in v0.1.1
func (api *API) ProcessBody(r *http.Request) (*RequestDataContext, error)
ProcessBody API request. You can to define request JSON format and how to validate it implemented the APIRequestReciver interface.
func (*API) ProcessEncryptedBody ¶ added in v0.1.1
func (api *API) ProcessEncryptedBody(r *http.Request) (*RequestEncryptedData, error)
ProcessEncryptedBody API request. You can to define request body encription and how to validate it implemented the APIRequestReciver interface.
func (*API) RegisterNewAPIRequestReceiver ¶ added in v0.1.1
func (api *API) RegisterNewAPIRequestReceiver(receiver APIRequestReceiver)
RegisterNewAPIRequestReceiver inject a new implementation in the APIRequestReceiver interface.
func (*API) RegisterNewAPIResponseFormatter ¶
func (api *API) RegisterNewAPIResponseFormatter(formatter APIResponseFormatter)
RegisterNewAPIResponseFormatter inject a new implementation in the APIResponseFormatter interface.
func (*API) RegisterNewAPIResponseWriter ¶
func (api *API) RegisterNewAPIResponseWriter(writer APIResponseWriter)
RegisterNewAPIResponseWriter inject a new implementation in the APIResponseWriter interface.
func (*API) RegisterNewAPISecurityGuarantor ¶ added in v0.1.1
func (api *API) RegisterNewAPISecurityGuarantor(guarantor APISecurityGuarantor)
RegisterNewAPISecurityGuarantor inject a new implementation in the APISecurityGuarantor interface
func (*API) RegisterParamValidator ¶ added in v0.1.8
RegisterParamValidator inject a new implementation in the Validator
func (API) UnmarshalBody ¶
UnmarshalBody parses request body to a struct.
func (*API) ValidateBasicToken ¶
ValidateBasicToken validate token with a basic auth token validation method.
func (*API) ValidateCustomToken ¶
func (api *API) ValidateCustomToken(token string, customValidator CustomTokenValidator) (json.RawMessage, bool)
ValidateCustomToken validate token with a custom method.
func (*API) ValidateMethods ¶
ValidateMethods validates if a method exist in a methods map.
func (API) ValidateParams ¶ added in v0.1.8
UnmarshalBody parses request body to a struct.
func (*API) Write ¶
func (api *API) Write(data ResponseData, w http.ResponseWriter)
Write API response in JSON format in screen. You can to define response JSON format implemented the APIResponseFormatter interface.
type APIRequestReceiver ¶ added in v0.1.1
type APIRequestReceiver interface {
// ProcessBody API request body information
ProcessBody(*http.Request) (*RequestDataContext, error)
// ProcessEncryptedBody API request url encode data
ProcessEncryptedBody(*http.Request) (*RequestEncryptedData, error)
// GetRouteVar returns the route var for the current request, if any.
GetRouteVar(string, *http.Request) string
}
APIRequestReceiver implemnt this interface to process request body information.
type APIResponseFormatter ¶
type APIResponseFormatter interface {
// Format the response body information.
Format(ResponseData) *ResponseFormatted
}
APIResponseFormatter implement this interface to format the API response information to JSON.
type APIResponseWriter ¶
type APIResponseWriter interface {
// Write the API response in screen.
Write(*ResponseFormatted, http.ResponseWriter)
}
APIResponseWriter implement this interface to write API response information in screen.
type APISecurityGuarantor ¶ added in v0.1.1
type APISecurityGuarantor interface {
// ValidateBasicToken validate a token with a basic authentication method.
ValidateBasicToken(token string) (client, secret string, valid bool)
// ValidateBasicToken validate a token with a custmo authentication method.
ValidateCustomToken(token string, validator CustomTokenValidator) (json.RawMessage, bool)
}
APISecurityGuarantor you can to implement this interface to implement authentication methos.
type CustomTokenValidator ¶
type CustomTokenValidator func(string) (json.RawMessage, bool)
CustomTokenValidator validator custom token function type. Implement this type to creat a custom token validation method as bearer authentication method or specific company methods.
type JSONContent ¶ added in v0.1.1
type JSONContent []byte
JSONContent use to set a json request body. Use to parse json request body to a structure.
func (JSONContent) Decode ¶ added in v0.1.1
func (content JSONContent) Decode(v interface{}) error
Decode func decodes json content to an any structure.
func (JSONContent) MarshalJSON ¶ added in v0.1.1
func (content JSONContent) MarshalJSON() ([]byte, error)
MarshalJSON returns m as the JSON encoding of m.
func (*JSONContent) UnmarshalJSON ¶ added in v0.1.1
func (content *JSONContent) UnmarshalJSON(data []byte) error
UnmarshalJSON sets *m to a copy of data.
type MapMethods ¶
MapMethods you can to use this map to define your methods that allow or block in your API module.
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 ParamValidator ¶ added in v0.1.8
ParamValidator function, return msg and error when param is incorrect
type RequestDataContext ¶ added in v0.1.10
type RequestDataContext struct {
context.Context
// Client device UUID
UUID string
// Client device type
DeviceType string
// Client device brand
DeviceBrand string
// Client device model
DeviceModel string
// Client device operating system
DeviceOS string
// Client device operating system version
OSVersion string
// Client device operating system timezone
OSTimezone string
// Client App language config
AppLanguage string
// Client App version
AppVersion string
// Client App build information
AppBuildInfo string
// Client App name
AppName string
// Client security token
SecurityToken string
// DeviceSerial device serial number
DeviceSerial string
// DeviceId device unique id
DeviceId string
// Latitude device latitude
Latitude string
// Longitude device longitude
Longitude string
// Request event ID
EventID string
// HTTP request headers
Headers map[string]string
// You can to use this map to extend request information
Info info.Info
// You can use this property to add the body content for your
// API request in json format.
Content JSONContent
// RawBody content
RawBody []byte
// Data contains more data
Data interface{}
}
RequestDataContext contains all information to process the API request.
func (*RequestDataContext) AddHeader ¶ added in v0.1.10
func (data *RequestDataContext) AddHeader(key, value string)
AddHeader adds new header to Headers map.
func (*RequestDataContext) AddInfo ¶ added in v0.1.10
func (data *RequestDataContext) AddInfo(key, value string)
AddInfo adds new item to AditionalInfo map.
func (*RequestDataContext) DecodeContent ¶ added in v0.1.10
func (data *RequestDataContext) DecodeContent(v interface{}) error
DecodeContent decodes RequestDataContext.Content property from json to a struct.
func (*RequestDataContext) Get ¶ added in v0.1.10
func (data *RequestDataContext) Get(key string) (value interface{})
Get additional info value.
func (*RequestDataContext) GetBool ¶ added in v0.1.10
func (data *RequestDataContext) GetBool(key string) bool
GetBool gets additional info value as bool.
func (*RequestDataContext) GetFloat ¶ added in v0.1.10
func (data *RequestDataContext) GetFloat(key string) float64
GetFloat gets additional ifno value as float64.
func (*RequestDataContext) GetInt ¶ added in v0.1.10
func (data *RequestDataContext) GetInt(key string) int
GetInt gets additional info value as int.
func (*RequestDataContext) GetInt64 ¶ added in v0.1.10
func (data *RequestDataContext) GetInt64(key string) int64
GetInt64 gets additional info value as int64.
func (*RequestDataContext) GetString ¶ added in v0.1.10
func (data *RequestDataContext) GetString(key string) string
GetString gets additional info value as string.
func (*RequestDataContext) GetStruct ¶ added in v0.1.10
func (data *RequestDataContext) GetStruct(key string, v interface{}) error
GetStruct unmarhal a struct in additional info map.
func (*RequestDataContext) Set ¶ added in v0.1.10
func (data *RequestDataContext) Set(key string, value interface{})
Set additional info value.
type RequestEncryptedData ¶ added in v0.1.1
type RequestEncryptedData struct {
context.Context
// Request Metadata
Metadata string
// Data contains more data
Data string
// You can to use this map to extend request information
Info info.Info
}
RequestEncryptedData contains all encryptions information to process the API request.
type ResponseData ¶
type ResponseData struct {
// Title of response
Title string
// Message descriptor response
Message string
// HTTP status code respose
HTTPStatusCode int
// Custom code of respoonse
ResponseCode ResponseCode
// Response type: error, success, warning, etc.
ResponseType ResponseType
// The user security token
SecurityToken string
// Indicate actions for devices.
Actions string
// Request unique identifier
EventID string
// Headers for HTTP response
Headers map[string]string
// You can to use this map to add custom informations to generate
// your API response.
Info map[string]string
// You can use this property to add the body content for your
// API response.
Content interface{}
}
ResponseData contain all information to generate the HTTP API response.
func (*ResponseData) AddHeader ¶
func (data *ResponseData) AddHeader(key, value string)
AddHeader adds new header to Headers map.
func (*ResponseData) AddInfo ¶ added in v0.1.1
func (data *ResponseData) AddInfo(key, value string)
AddInfo adds new item to AditionalInfo map.
type ResponseFormatted ¶
ResponseFormatted contain formatted information to be responsed.
type ResponseType ¶
type ResponseType string
ResponseType contains all the response types identifers