httputil

package
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AuthUserKey = "username"
	AuthPassKey = "password"
)
View Source
const (
	TraceIDHeaderKey          = "Trace-Id"
	ConsumerIdHeaderKey       = "Consumer-ID"
	SubjectTokenTypeHeaderKey = "Subject-Token-Type"
	SubjectTokenHeaderKey     = "Subject-Token"
)
View Source
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

func BasicAuthError(ctx *gin.Context)

BasicAuthError writes an errors to the gin context if basic authentication is not provided

func BasicAuthFailed

func BasicAuthFailed(ctx *gin.Context)

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 GenerateTraceId(ctx *gin.Context)

func GetBasicAuthFromHeader

func GetBasicAuthFromHeader(ctx *gin.Context) *errors.Error

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 Health

func Health(ctx *gin.Context)

Health controller handles requests on the /health endpoint.

func MethodNotAllowed

func MethodNotAllowed(ctx *gin.Context)

MethodNotAllowed method not allowed controller handles request on known endpoints but on methods that are not configured

func NewRouter

func NewRouter() *gin.Engine

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

func NewStringToJsonResponder(statusCode int, body string) httpmock.Responder

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.

func NoRoute

func NoRoute(ctx *gin.Context)

NoRoute no route controller handles request on endpoints that are not configured

Types

type RestErr

type RestErr struct {
	Error string `json:"error"`
}

RestErr represents an error returned by a REST API

type RestMsg

type RestMsg struct {
	Message string `json:"message"`
}

RestMsg represents a message returned by a REST API

Jump to

Keyboard shortcuts

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