Documentation
¶
Index ¶
- Constants
- Variables
- func AddNewMapMethod(key string, methods []string)
- func AddSkipPath(path SkipPath, skip bool)
- func BasicToken(next http.HandlerFunc) http.HandlerFunc
- func CustomToken(next http.HandlerFunc) http.HandlerFunc
- func Delete(router Router, path string, handler http.HandlerFunc, opts ...doc.RouteOption)
- func DeleteSkipPath(path SkipPath)
- func Get(router Router, path string, handler http.HandlerFunc, opts ...doc.RouteOption)
- func GetContextValue(key interface{}, r *http.Request) interface{}
- func LogRequest(method, uri, eventID, form string, headers http.Header, rawBody []byte)
- func LogResponse(eventID string, res *httptest.ResponseRecorder)
- func LogResponseWithDuration(eventID string, res *httptest.ResponseRecorder, duration time.Duration)
- func NewRequestBodyMiddleware(keyListMethods string) core.Middleware
- func ParamValidatorV0(v any) (string, error)
- func Patch(router Router, path string, handler http.HandlerFunc, opts ...doc.RouteOption)
- func Post(router Router, path string, handler http.HandlerFunc, opts ...doc.RouteOption)
- func ProcessRequest(next http.HandlerFunc) http.HandlerFunc
- func Put(router Router, path string, handler http.HandlerFunc, opts ...doc.RouteOption)
- func RegisterAdapter(name string, factory AdapterFactory)
- func RegisterAuth(name string, provider AuthProvider)
- func RegisterCodec(name string, codec Codec)
- func RegisterCrypto(name string, provider CryptoProvider)
- func RegisterNewAPIRequestReceiver(receiver core.APIRequestReceiver)
- func RegisterNewAPIResponseFormatter(formatter core.APIResponseFormatter)
- func RegisterNewAPIResponseWriter(writer core.APIResponseWriter)
- func RegisterNewAPISecurityGuarantor(guarantor core.APISecurityGuarantor)
- func RegisterParamValidator(paramValidator func(any) (errMsg string, err error))
- func RegisterTraceIDProvider(provider TraceIDProvider)
- func RegisterTraceProvider(name string, provider TraceIDProvider)
- func RegisterValidator(name string, validator Validator)
- func RequestHeaderJSON(next http.HandlerFunc) http.HandlerFunc
- func RequestHeaderSession(next http.HandlerFunc) http.HandlerFunc
- func SetContextValue(key, value interface{}, r *http.Request) *http.Request
- func SetRequestMode(mode RequestMode)
- func SetResponseMode(mode ResponseMode)
- func SetRouteVars(vars map[string]string, r *http.Request) *http.Request
- func UpdateRequestContext(requestData *RequestContext, r *http.Request) *http.Request
- func ValidateBasicToken(token string) (client, secret string, valid bool)
- func ValidateCustomToken(token string) (json.RawMessage, bool)
- func ValidateMethods(keyMapMethod, method string) bool
- func Write(data core.ResponseData, w http.ResponseWriter)
- type AdapterFactory
- type AuthProvider
- type AuthResult
- type Codec
- type CryptoProvider
- type EncryptedRequest
- type Error
- type Informative
- type RequestBasic
- func (request *RequestBasic) GetEventID() Response
- func (request *RequestBasic) GetRequestBasicInfo() Response
- func (request *RequestBasic) GetRequestFullInfo() Response
- func (request *RequestBasic) GetSecurityToken() Response
- func (request *RequestBasic) GetUserID() Response
- func (request *RequestBasic) UnmarshalBody() Response
- type RequestContext
- type RequestContextKey
- type RequestMode
- type RequestReceiver
- type RequestReceiverV2
- type Response
- func GetHeaderValueBool(key string, r *http.Request) (bool, Response)
- func GetHeaderValueFloat64(key string, r *http.Request) (float64, Response)
- func GetHeaderValueInt(key string, r *http.Request) (int, Response)
- func GetHeaderValueInt64(key string, r *http.Request) (int64, Response)
- func GetHeaderValueString(key string, r *http.Request) (string, Response)
- func GetQueryParamValueBool(queryParamName string, r *http.Request) (bool, Response)
- func GetQueryParamValueFloat64(queryParamName string, r *http.Request) (float64, Response)
- func GetQueryParamValueInt(queryParamName string, r *http.Request) (int, Response)
- func GetQueryParamValueInt64(queryParamName string, r *http.Request) (int64, Response)
- func GetQueryParamValueString(queryParamName string, r *http.Request) (string, Response)
- func GetRouteVarValueBool(urlVarName string, r *http.Request) (bool, Response)
- func GetRouteVarValueFloat64(urlVarName string, r *http.Request) (float64, Response)
- func GetRouteVarValueInt(urlVarName string, r *http.Request) (int, Response)
- func GetRouteVarValueInt64(urlVarName string, r *http.Request) (int64, Response)
- func GetRouteVarValueString(urlVarName string, r *http.Request) (string, Response)
- func UnmarshalBody(v interface{}, r *http.Request) Response
- type ResponseFormatter
- type ResponseMode
- type ResponseWriter
- type Router
- type SecurityGuaranter
- type SkipPath
- type Success
- type TraceIDProvider
- type ValidateCredentials
- type Validator
- type Warning
Constants ¶
const MethodGetKey = "get"
MethodGetKey GET http method key ..
const MethodPatchKey = "patch"
MethodPatchKey PATCH http method key ..
const MethodPostKey = "post"
MethodPostKey POST http method key ..
const MethodPutKey = "put"
MethodPutKey PUT http method key ..
const PPMethodsKey = "pp"
PPMethodsKey POST and PUT http methods ..
const PPPGMethodsKey = "pppg"
PPPGMethodsKey POST, PUT, PATCH, and GET http methods ..
const PPPMethodsKey = "ppp"
PPPMethodsKey POST, PUT and PATCH http methods ..
const RequestDataContextContextKey = RequestContextKey("requestData")
RequestDataContextContextKey request data context key to finds request context
Variables ¶
var ( // DefaultInvalidAuthHeaderMsg default invalid authorization message. DefaultInvalidAuthHeaderMsg = "Invalid Authorization header!" DefaultBasicUnauthorizedMsg = "Invalid basic token" DefaultBearerUnauthorizedMsg = "Invalid bearer token" // CustomTokenPrefix custom token authorization method prefix. CustomTokenPrefix = "Bearer" DefaultCustomUnauthorizedMsg = fmt.Sprintf("Invalid %v token", CustomTokenPrefix) )
var ( // DefaultErrorTitle default error title. DefaultErrorTitle = "Error response!" // DefaultErrorMessage default error message. DefaultErrorMessage = "The service has not completed the operation!" // ErrorType error response type the value is "error". ErrorType core.ResponseType = "error" // InternalServerTitle internal server error title. InternalServerTitle = "Sorry!" // InternalServerMessage internal server error message. InternalServerMessage = "An error has occurred please try again later." UnauthorizedTitle = "Unauthorized!" UnauthorizedMessage = "User not authorized." )
var ( // DefaultInfoTitle default informative title. DefaultInfoTitle = "Information!" // DefaultInfoMessage default informative message. DefaultInfoMessage = "The request has been successful!" // InformativeType info response type the value is "info". InformativeType core.ResponseType = "info" // DefaultInfoCode default informative code. DefaultInfoCode = "0000" )
var ( // DefaultSuccessTitle default success title. DefaultSuccessTitle = "Successful!" // DefaultSuccessMessage default success message. DefaultSuccessMessage = "The request has been successful!" // SuccessType success response type the value is "success". SuccessType core.ResponseType = "success" // DefaultSuccessCode default success code. DefaultSuccessCode = "0000" )
var ( // DefaultWarningTitle default warning title. DefaultWarningTitle = "Alert!" // DefaultWarningMessage default warning message. DefaultWarningMessage = "The application has been successful but with potential problems!" // WarningType warning response type the value is "warning" WarningType core.ResponseType = "warning" // DefaultWarningCode default warning code. DefaultWarningCode = "0000" )
var ( // Username basic authentication // Default: admin // Change this, it's insecure. Username = "default" // Password basic authentication // Default: admin // Change this, it's insecure. Password = "default" )
var BlankSuccess = true
BlankSuccess contols if success include user feeback information
var CurrentRequestMode = RequestModePlain
CurrentRequestMode defines the active request parsing mode.
var CurrentResponseMode = ResponseModeEnvelope
CurrentResponseMode defines the active response formatting mode.
var CustomTokenValidatorFunc core.CustomTokenValidator
CustomTokenValidatorFunc define custom function to validate custom token.
var EventIDHeaderKey = "EventID"
EventIDHeaderKey event ID header key.
var Fatal func(...interface{}) = log.Fatal
Fatal wrapper function.
var GetRouteVar func(string, *http.Request) string = func(key string, r *http.Request) string {
return getRouteVarFromContext(key, r)
}
GetRouteVar returns the route variables for the current request, if any define it as: api.GetRouteVar = myCustomGetRouteVarFunc
var LogRequestBody bool = false
LogRequestBody enables request body logging.
var LogResponseBody bool = false
LogResponseBody enables response body logging.
var MaxLoggedBodyBytes int = 2000
MaxLoggedBodyBytes limits logged request and response bodies when PrintFullEvent is false.
var MiddlewaresChain = core.MiddlewaresChain
MiddlewaresChain provides syntactic sugar to create a new middleware which will be the result of chaining the ones received as parameters
var Print func(string, ...interface{}) = log.Printf
Print wrapper function.
var PrintError func(...interface{}) = log.Print
PrintError wrapper function.
var PrintFullEvent bool = false
PrintFullEvent set true value for allow print full event request
var RequestBody = NewRequestBodyMiddleware(PPPMethodsKey)
RequestBody wrapper middleware
var ResponseCodes = struct { Success core.ResponseCode Informative core.ResponseCode Warning core.ResponseCode DefaultError core.ResponseCode InvalidJSON core.ResponseCode InvalidRequestURL core.ResponseCode ValidationError core.ResponseCode MissingVersionError core.ResponseCode Unauthorized core.ResponseCode ObjectNotFound core.ResponseCode RestrictResource core.ResponseCode InternalServerEerror core.ResponseCode ServiceUnavailable core.ResponseCode InvalidParams core.ResponseCode }{ Success: "0000", Informative: "0000", Warning: "0000", DefaultError: "E001", InvalidJSON: "E002", InvalidRequestURL: "E003", ValidationError: "E004", MissingVersionError: "E005", Unauthorized: "B001", RestrictResource: "B002", ObjectNotFound: "E006", InternalServerEerror: "E300", ServiceUnavailable: "E301", InvalidParams: "A101", }
ResponseCodes catalog
var SecurityTokenHeaderKey = "SecurityToken"
SecurityTokenHeaderKey session ID header key.
var SensitiveLogKeys = []string{
"authorization",
"token",
"password",
"secret",
"credential",
"apikey",
"api-key",
"key",
}
SensitiveLogKeys defines fields and headers that must be redacted in logs.
var SkipPaths map[SkipPath]bool
var TraceIDLength = 6
TraceIDLength specifies the number of characters to return from the beginning of the input trace ID.
var TraceVisibility = 1
TraceVisibility controls how trace information is included in the response message. - 1: Includes both event ID and response code. - 2: Includes only the Code. - 3: Includes only the event ID.
var UserIDHeaderKey = "UserID"
UserIDHeaderKey User ID header key.
Functions ¶
func AddNewMapMethod ¶
AddNewMapMethod add a new method in a map of methods.
func AddSkipPath ¶ added in v0.1.12
func BasicToken ¶
func BasicToken(next http.HandlerFunc) http.HandlerFunc
BasicToken validates basic authentication token middleware.
func CustomToken ¶
func CustomToken(next http.HandlerFunc) http.HandlerFunc
CustomToken middleware to validates custom token authorization method.
func Delete ¶ added in v0.1.13
func Delete(router Router, path string, handler http.HandlerFunc, opts ...doc.RouteOption)
Delete registers a DELETE route in a router adapter.
func DeleteSkipPath ¶ added in v0.1.12
func DeleteSkipPath(path SkipPath)
func Get ¶ added in v0.1.13
func Get(router Router, path string, handler http.HandlerFunc, opts ...doc.RouteOption)
Get registers a GET route in a router adapter.
func GetContextValue ¶ added in v0.1.1
GetContextValue gets requesst context value from context key.
func LogRequest ¶
LogRequest prints API request in log.
func LogResponse ¶
func LogResponse(eventID string, res *httptest.ResponseRecorder)
LogResponse prints API response in log.
func LogResponseWithDuration ¶ added in v0.2.1
func LogResponseWithDuration(eventID string, res *httptest.ResponseRecorder, duration time.Duration)
LogResponseWithDuration prints API response in log including request duration.
func NewRequestBodyMiddleware ¶
func NewRequestBodyMiddleware(keyListMethods string) core.Middleware
NewRequestBodyMiddleware doc ...
func ParamValidatorV0 ¶ added in v0.1.8
func Patch ¶ added in v0.1.13
func Patch(router Router, path string, handler http.HandlerFunc, opts ...doc.RouteOption)
Patch registers a PATCH route in a router adapter.
func Post ¶ added in v0.1.13
func Post(router Router, path string, handler http.HandlerFunc, opts ...doc.RouteOption)
Post registers a POST route in a router adapter.
func ProcessRequest ¶ added in v0.1.1
func ProcessRequest(next http.HandlerFunc) http.HandlerFunc
ProcessRequest process request information.
func Put ¶ added in v0.1.13
func Put(router Router, path string, handler http.HandlerFunc, opts ...doc.RouteOption)
Put registers a PUT route in a router adapter.
func RegisterAdapter ¶ added in v0.2.0
func RegisterAdapter(name string, factory AdapterFactory)
RegisterAdapter registers a router adapter factory.
func RegisterAuth ¶ added in v0.2.0
func RegisterAuth(name string, provider AuthProvider)
RegisterAuth registers an authentication provider.
func RegisterCodec ¶ added in v0.2.0
RegisterCodec registers a response serialization codec.
func RegisterCrypto ¶ added in v0.2.0
func RegisterCrypto(name string, provider CryptoProvider)
RegisterCrypto registers an encryption/decryption provider.
func RegisterNewAPIRequestReceiver ¶ added in v0.1.1
func RegisterNewAPIRequestReceiver(receiver core.APIRequestReceiver)
RegisterNewAPIRequestReceiver inject a new implementation in the core.APIRequestReceiver interface.
func RegisterNewAPIResponseFormatter ¶
func RegisterNewAPIResponseFormatter(formatter core.APIResponseFormatter)
RegisterNewAPIResponseFormatter inject a new implementation in the APIResponseFormatter interface.
func RegisterNewAPIResponseWriter ¶
func RegisterNewAPIResponseWriter(writer core.APIResponseWriter)
RegisterNewAPIResponseWriter inject a new implementation in the core.APIResponseWriter interface.
func RegisterNewAPISecurityGuarantor ¶ added in v0.1.1
func RegisterNewAPISecurityGuarantor(guarantor core.APISecurityGuarantor)
RegisterNewAPISecurityGuarantor inject a new implementation in the core.APISecurityGuarantor interface
func RegisterParamValidator ¶ added in v0.1.8
RegisterParamValidator inject a new implementation in the Validator
func RegisterTraceIDProvider ¶ added in v0.1.14
func RegisterTraceIDProvider(provider TraceIDProvider)
RegisterTraceIDProvider configures the provider used to derive event IDs from context.
func RegisterTraceProvider ¶ added in v0.2.0
func RegisterTraceProvider(name string, provider TraceIDProvider)
RegisterTraceProvider registers a named trace ID provider.
func RegisterValidator ¶ added in v0.2.0
RegisterValidator registers a validation provider.
func RequestHeaderJSON ¶
func RequestHeaderJSON(next http.HandlerFunc) http.HandlerFunc
RequestHeaderJSON validate header Content-Type, is required and equal to application/json
func RequestHeaderSession ¶
func RequestHeaderSession(next http.HandlerFunc) http.HandlerFunc
RequestHeaderSession validates that session ID is valid.
func SetContextValue ¶ added in v0.1.1
SetContextValue sets requesst context value from context key.
func SetRequestMode ¶ added in v0.2.1
func SetRequestMode(mode RequestMode)
SetRequestMode updates the request parsing mode.
func SetResponseMode ¶ added in v0.2.1
func SetResponseMode(mode ResponseMode)
SetResponseMode updates the response formatting mode.
func SetRouteVars ¶ added in v0.1.13
SetRouteVars stores route variables in the request context.
func UpdateRequestContext ¶ added in v0.1.1
func UpdateRequestContext(requestData *RequestContext, r *http.Request) *http.Request
UpdateRequestContext update request context.
func ValidateBasicToken ¶
ValidateBasicToken validate token with a basic auth token validation method.
func ValidateCustomToken ¶
func ValidateCustomToken(token string) (json.RawMessage, bool)
ValidateCustomToken validate token with a custom method.
func ValidateMethods ¶ added in v0.1.1
ValidateMethods validates if a method exist in a methods map.
func Write ¶ added in v0.1.1
func Write(data core.ResponseData, w http.ResponseWriter)
Write API response in JSON format in screen. You can to define response JSON format implemented the APIResponseFormatter interface.
Types ¶
type AdapterFactory ¶ added in v0.2.0
AdapterFactory creates a Router from an adapter-specific target.
type AuthProvider ¶ added in v0.2.0
type AuthProvider interface {
Authenticate(r *http.Request) (*AuthResult, error)
}
AuthProvider authenticates an HTTP request.
func AuthByName ¶ added in v0.2.0
func AuthByName(name string) (AuthProvider, error)
AuthByName returns a registered authentication provider.
type AuthResult ¶ added in v0.2.0
AuthResult contains normalized authentication data returned by an AuthProvider.
type Codec ¶ added in v0.2.0
Codec serializes response bodies.
func CodecByName ¶ added in v0.2.0
CodecByName returns a registered response serialization codec.
type CryptoProvider ¶ added in v0.2.0
type CryptoProvider interface {
Encrypt(ctx context.Context, plaintext []byte) ([]byte, error)
Decrypt(ctx context.Context, ciphertext []byte) ([]byte, error)
}
CryptoProvider encrypts and decrypts payload bytes.
func CryptoByName ¶ added in v0.2.0
func CryptoByName(name string) (CryptoProvider, error)
CryptoByName returns a registered encryption/decryption provider.
type EncryptedRequest ¶ added in v0.1.1
type EncryptedRequest struct {
*core.RequestEncryptedData
}
EncryptedRequest documentation ...
func ProcessEncryptedBody ¶ added in v0.1.1
func ProcessEncryptedBody(r *http.Request) (*EncryptedRequest, error)
ProcessEncryptedBody API request. You can to define request url encoding format and how to validate it implemented the APIRequestReciver interface.
type Error ¶
type Error core.ResponseData
Error error response type the value is "error".
func Error401 ¶ added in v0.1.1
func Error401() Error
Error401 returns a new HTTP Unauthorized error cod. and unauthorized error defalut title and default message.
func Error403 ¶ added in v0.1.1
func Error403() Error
Error403 returns a new HTTP Forbiden error code and unauthorized error defalut title and default message.
func Error500 ¶ added in v0.1.1
Error500 returns a new HTTP Internal Server Error code. and internal server error default title and default mesage.
func Error500WithMsg ¶ added in v0.1.1
Error500WithMsg returns a new HTTP internal server error code with custom message.
func Error501 ¶ added in v0.1.1
Error501 returns a new HTTP Not Implement Error code. and internal server error default title and default mesage.
func ErrorWithMsg ¶ added in v0.1.1
ErrorWithMsg return a new HTTP Bad Request with custom message.
type Informative ¶
type Informative core.ResponseData
Informative info response type the value is "info".
func (Informative) Write ¶
func (info Informative) Write(w http.ResponseWriter, r *http.Request)
Write informative message in screen.
type RequestBasic ¶
type RequestBasic struct {
JSONStruct interface{}
SessionID string
UserID string
EventID string
HTTPReq *http.Request
}
RequestBasic doc ...
func (*RequestBasic) GetEventID ¶ added in v0.1.1
func (request *RequestBasic) GetEventID() Response
GetEventID gets event ID by header key layout.
func (*RequestBasic) GetRequestBasicInfo ¶
func (request *RequestBasic) GetRequestBasicInfo() Response
GetRequestBasicInfo gets session ID, user ID and event ID.
func (*RequestBasic) GetRequestFullInfo ¶
func (request *RequestBasic) GetRequestFullInfo() Response
GetRequestFullInfo gets session ID, userID, event ID and unmarshal request body.
func (*RequestBasic) GetSecurityToken ¶ added in v0.1.1
func (request *RequestBasic) GetSecurityToken() Response
GetSecurityToken gets security token from user by header key layout.
func (*RequestBasic) GetUserID ¶
func (request *RequestBasic) GetUserID() Response
GetUserID gets id user ID by header key layout.
func (*RequestBasic) UnmarshalBody ¶
func (request *RequestBasic) UnmarshalBody() Response
UnmarshalBody parses request body to a struct.
type RequestContext ¶ added in v0.1.10
type RequestContext struct {
*core.RequestDataContext
}
Request contains all information to process the API request. Wrapper of core.RequestDataContext
func Context ¶ added in v0.1.10
func Context(ctx context.Context) *RequestContext
func GetRequestContext ¶ added in v0.1.1
func GetRequestContext(r *http.Request) (*RequestContext, error)
GetRequestContext gets request data from http request context. This useful when you set Request type of core.RequestDataContext in http request context in a middleware implementation. Returns a core.RequestDataContext struct from api.RequestDataContextContextKey key.
func ProcessBody ¶ added in v0.1.1
func ProcessBody(r *http.Request) (*RequestContext, error)
ProcessBody API request. You can to define request JSON format and how to validate it implemented the APIRequestReciver interface.
func RContext ¶ added in v0.1.10
func RContext(ctx context.Context) (*RequestContext, error)
RContext gets request data from http request context. This useful when you set Request type of core.RequestDataContext in http request context in a middleware implementation. Returns a core.RequestDataContext struct from api.RequestDataContextContextKey key.
type RequestMode ¶ added in v0.2.1
type RequestMode string
RequestMode controls how request payloads are parsed.
const ( RequestModeNone RequestMode = "none" RequestModePlain RequestMode = "plain" RequestModeEnvelope RequestMode = "envelope" RequestModeAuto RequestMode = "auto" )
type RequestReceiver ¶ added in v0.1.1
type RequestReceiver struct{}
RequestReceiver implementation of core.APIRequestReceiver interface
func (RequestReceiver) GetRouteVar ¶ added in v0.1.1
func (receiver RequestReceiver) GetRouteVar(key string, r *http.Request) string
GetRouteVar returns the route variables for the current request, if any
func (RequestReceiver) ProcessBody ¶ added in v0.1.1
func (receiver RequestReceiver) ProcessBody(r *http.Request) (*core.RequestDataContext, error)
ProcessBody process API request body information.
func (RequestReceiver) ProcessEncryptedBody ¶ added in v0.1.1
func (receiver RequestReceiver) ProcessEncryptedBody(r *http.Request) (*core.RequestEncryptedData, error)
ProcessEncryptedBody process API request encription information.
type RequestReceiverV2 ¶ added in v0.1.1
type RequestReceiverV2 struct{}
RequestReceiverV2 implementation of core.APIRequestReceiver interface
func (RequestReceiverV2) GetRouteVar ¶ added in v0.1.1
func (receiver RequestReceiverV2) GetRouteVar(key string, r *http.Request) string
GetRouteVar returns the route variables for the current request, if any
func (RequestReceiverV2) ProcessBody ¶ added in v0.1.1
func (receiver RequestReceiverV2) ProcessBody(r *http.Request) (*core.RequestDataContext, error)
ProcessBody API request body information.
func (RequestReceiverV2) ProcessEncryptedBody ¶ added in v0.1.1
func (receiver RequestReceiverV2) ProcessEncryptedBody(r *http.Request) (*core.RequestEncryptedData, error)
ProcessEncryptedBody API request encription information.
type Response ¶
type Response interface {
Write(w http.ResponseWriter, r *http.Request)
}
Response wrapper to generate core responses.
func GetHeaderValueBool ¶
GetHeaderValueBool gets header values as bool.
func GetHeaderValueFloat64 ¶
GetHeaderValueFloat64 gets header value as float 64.
func GetHeaderValueInt ¶
GetHeaderValueInt gets header value as integer.
func GetHeaderValueInt64 ¶
GetHeaderValueInt64 gets header value as integer 64.
func GetHeaderValueString ¶
GetHeaderValueString gets header value as string.
func GetQueryParamValueBool ¶
GetQueryParamValueBool gets param value as bool.
func GetQueryParamValueFloat64 ¶
GetQueryParamValueFloat64 gets query param value as float 64.
func GetQueryParamValueInt ¶
GetQueryParamValueInt gets query param value as integer.
func GetQueryParamValueInt64 ¶
GetQueryParamValueInt64 gets query param value as integer 64.
func GetQueryParamValueString ¶
GetQueryParamValueString gets query param value as string.
func GetRouteVarValueBool ¶
GetRouteVarValueBool gets route variable value as bool.
func GetRouteVarValueFloat64 ¶
GetRouteVarValueFloat64 gets route variable value as float 64.
func GetRouteVarValueInt ¶
GetRouteVarValueInt gets route variable value as integer.
func GetRouteVarValueInt64 ¶
GetRouteVarValueInt64 gets route variable value as integer 64.
func GetRouteVarValueString ¶
GetRouteVarValueString gets route variable value as string.
func UnmarshalBody ¶
UnmarshalBody parses and validates request body to a struct
type ResponseFormatter ¶
type ResponseFormatter struct{}
ResponseFormatter implementation of core.APIResponseFormatter interface.
func (ResponseFormatter) Format ¶
func (formatter ResponseFormatter) Format(data core.ResponseData) *core.ResponseFormatted
Format the response body information.
type ResponseMode ¶ added in v0.2.1
type ResponseMode string
ResponseMode controls how response payloads are formatted.
const ( ResponseModeNone ResponseMode = "none" ResponseModePlain ResponseMode = "plain" ResponseModeEnvelope ResponseMode = "envelope" )
type ResponseWriter ¶
type ResponseWriter struct{}
ResponseWriter implementation of core.APIResponseWriter interface.
func (ResponseWriter) Write ¶
func (writer ResponseWriter) Write(response *core.ResponseFormatted, w http.ResponseWriter)
Write the API response in screen.
type Router ¶ added in v0.1.13
type Router interface {
Handle(method string, path string, handler http.HandlerFunc, opts ...doc.RouteOption)
}
Router is the minimal contract implemented by router adapters.
type SecurityGuaranter ¶ added in v0.1.1
type SecurityGuaranter struct{}
SecurityGuaranter implementation of core.APISecurityGuaranter interface.
func (*SecurityGuaranter) ValidateBasicToken ¶ added in v0.1.1
func (guaranter *SecurityGuaranter) ValidateBasicToken(token string) (client, secret string, valid bool)
ValidateBasicToken validate token with a basic auth token validation method.
func (*SecurityGuaranter) ValidateCustomToken ¶ added in v0.1.1
func (guaranter *SecurityGuaranter) ValidateCustomToken(token string, validator core.CustomTokenValidator) (json.RawMessage, bool)
ValidateCustomToken validate token with a custom method.
type Success ¶
type Success core.ResponseData
Success success response type the value is "success".
func Success200 ¶ added in v0.1.1
func Success200() Success
Success200 returns a HTTP success response with status code 200.
func Success201 ¶ added in v0.1.1
func Success201() Success
Success201 returns a HTTP Created success response with status code 200.
func SuccessWithContent ¶ added in v0.1.1
func SuccessWithContent(content interface{}) Success
SuccessWithContent returns a HTTP OK response with conttent response.
func SuccessWithMsg ¶ added in v0.1.1
SuccessWithMsg returns a HTTP OK response with a custom message.
type TraceIDProvider ¶ added in v0.1.14
TraceIDProvider retrieves a trace ID from a context.
func TraceProviderByName ¶ added in v0.2.0
func TraceProviderByName(name string) (TraceIDProvider, error)
TraceProviderByName returns a registered trace ID provider.
type ValidateCredentials ¶
ValidateCredentials func type.
var ValidateBasicAuthCredentialsFunc ValidateCredentials = validateCredentials
ValidateBasicAuthCredentialsFunc define custom function for validate basic authentication credential.
type Validator ¶ added in v0.2.0
Validator validates a decoded value.
func ValidatorByName ¶ added in v0.2.0
ValidatorByName returns a registered validation provider.
Source Files
¶
- adapters.go
- api.go
- auth.go
- basic_request.go
- catalogs.go
- codec.go
- crypto.go
- functions.go
- middlewares.go
- modes.go
- request_data.go
- request_validator.go
- request_validator_v2.go
- response.go
- response_error.go
- response_formatter.go
- response_informative.go
- response_success.go
- response_warning.go
- router.go
- security.go
- trace.go
- validator.go
Directories
¶
| Path | Synopsis |
|---|---|
|
Package doc contains OpenAPI documentation metadata, schema generation, and handlers.
|
Package doc contains OpenAPI documentation metadata, schema generation, and handlers. |
|
Package envelope contains shared JSON request and response envelope contracts.
|
Package envelope contains shared JSON request and response envelope contracts. |