Documentation ¶
Index ¶
- Constants
- func BasicAuth(accounts map[string]string) gin.HandlerFunc
- func BasicAuthError(ctx *gin.Context)
- func BasicAuthFailed(ctx *gin.Context)
- func BasicAuthRequired() gin.HandlerFunc
- func GenerateTraceId(ctx *gin.Context)
- func GetBasicAuthFromHeader(ctx *gin.Context) *errors.Error
- func GetServerURL(sc *config.ServerConfig, apiBasePath string) *url.URL
- func Health(ctx *gin.Context)
- func MethodNotAllowed(ctx *gin.Context)
- func NewRouter() *gin.Engine
- func NewStringToJsonResponder(statusCode int, body string) httpmock.Responder
- func NoRoute(ctx *gin.Context)
- type RestErr
- type RestMsg
Constants ¶
const ( AuthUserKey = "username" AuthPassKey = "password" )
const ( TraceIDHeaderKey = "Trace-Id" ConsumerIdHeaderKey = "Consumer-ID" SubjectTokenTypeHeaderKey = "Subject-Token-Type" SubjectTokenHeaderKey = "Subject-Token" )
const ( ServerStartupMsg = "Starting the API server" ServerStartupSuccessMsg = "The API server has started and is listening on %s" ServerUrlMsg = "API server url: %s" ServerAPIDocsMsg = "API server swagger docs url: %s" ApiHealthPath = "/health" ContentTypeHeaderKey = "Content-Type" AcceptHeaderKey = "Accept" AuthorizationHeaderKey = "Authorization" ApplicationJsonMIMEType = "application/json" TextPlainMIMEType = "text/plain" XWWWFromUrlEncodeMIMEType = "application/x-www-form-urlencoded" SwaggerPath = "/swagger/*any" SwaggerSpecPathFormat = "%s/swagger/doc.json" SwaggerUriPathFormat = "%s/swagger/index.html" )
Variables ¶
This section is empty.
Functions ¶
func BasicAuth ¶
func BasicAuth(accounts map[string]string) gin.HandlerFunc
BasicAuth is a gin middleware for validation if basic authentication is provided in the request and the auth user and password matches with the stored user accounts. The method writes the basic auth to the gin context The method returns an errors if basic authentication is not set and if the authentication fails to match with a user account.
func BasicAuthError ¶
BasicAuthError writes an errors to the gin context if basic authentication is not provided
func BasicAuthFailed ¶
BasicAuthFailed writes a errors to the gin context if basic authentication fails
func BasicAuthRequired ¶
func BasicAuthRequired() gin.HandlerFunc
BasicAuthRequired is a gin middleware for checking if basic authentication is provided in the request The method writes the basic auth to the gin context The method returns an errors if basic authentication is not set
func GenerateTraceId ¶
func GetBasicAuthFromHeader ¶
GetBasicAuthFromHeader gets basics authentication from the Authorization header.
func GetServerURL ¶
func GetServerURL(sc *config.ServerConfig, apiBasePath string) *url.URL
GetServerURL formats and returns the server url.
func MethodNotAllowed ¶
MethodNotAllowed method not allowed controller handles request on known endpoints but on methods that are not configured
func NewRouter ¶
NewRouter returns a new gin router which is configured with some settings for logging, auto recovery in case of panics and default handlers for NoRoute and MethodNotAllowed.
func NewStringToJsonResponder ¶
NewStringToJsonResponder is a custom httpmock.Responder that takes the status code and a json string body and creates a responder for a http mock. This is a useful function when unit testing rest API responses.