middleware

package
v0.0.0-...-8aeb8a1 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AdminTokenErr = "Admin token does not match"
	AdminTokenKey = "X-Admin-Token"
)
View Source
const (
	TokenName        = "token"
	APIKeyName       = "api_key"
	TokenHeaderName  = "x-auth-token"
	ErrTokenNotFound = "The token is not found: %s"

	JitsuAnonymIDCookie   = "__eventn_id"
	CookiePolicyParameter = "cookie_policy"
	IPPolicyParameter     = "ip_policy"

	KeepValue   = "keep"
	StrictValue = "strict"
	ComplyValue = "comply"
)
View Source
const (
	StatusOK      = "ok"
	StatusPending = "pending"
)

Variables

This section is empty.

Functions

func Cors

func Cors(h http.Handler, isAllowedOriginsFunc func(string) ([]string, bool)) http.Handler

Cors handles OPTIONS requests and check if request /event or dynamic event endpoint or static endpoint (/t /s /p) if token ok => check origins - if matched write origin to acao header otherwise don't write it if not returns 401

func ErrorLogWriter

func ErrorLogWriter(ctx *gin.Context)

func ExtractIP

func ExtractIP(c *gin.Context) string

ExtractIP extracts IP from the input request

func GinLogErrorBody

func GinLogErrorBody(c *gin.Context)

func TokenAuth

func TokenAuth(main gin.HandlerFunc, originalToken string) gin.HandlerFunc

TokenAuth check that provided token equals

func TokenFuncAuth

func TokenFuncAuth(main gin.HandlerFunc, isAllowedOriginsFunc func(string) ([]string, bool), errMsg string) gin.HandlerFunc

TokenFuncAuth check that provided token: 1. is valid 2. exists in specific (js or api) token config

func TokenTwoFuncAuth

func TokenTwoFuncAuth(main gin.HandlerFunc, isAllowedOriginsFunc func(string) ([]string, bool), anotherTypeAllowedOriginsFunc func(string) ([]string, bool), errMsg string) gin.HandlerFunc

TokenTwoFuncAuth check that provided token: 1. is valid 2. exists in specific (js or api) token config if not return err msg depend on existing in another token config

Types

type AdminToken

type AdminToken struct {
	Token string
}

func (*AdminToken) AdminAuth

func (a *AdminToken) AdminAuth(main gin.HandlerFunc) gin.HandlerFunc

type ErrorResponse

type ErrorResponse struct {
	Message string      `json:"message"`
	Payload interface{} `json:"payload,omitempty"`
	//Deprecated
	Error string `json:"error"`
}

ErrorResponse is a dto for sending error response

func ErrResponse

func ErrResponse(msg string, err error) *ErrorResponse

ErrResponse is a constructor for ErrorResponse

type GinErrorBodyWriter

type GinErrorBodyWriter struct {
	gin.ResponseWriter
	// contains filtered or unexported fields
}

func (*GinErrorBodyWriter) Write

func (gebw *GinErrorBodyWriter) Write(b []byte) (int, error)

type StatusResponse

type StatusResponse struct {
	Status  string `json:"status"`
	Message string `json:"message,omitempty"`
}

StatusResponse is a dto for sending operation status

func OKResponse

func OKResponse() StatusResponse

OKResponse returns StatusResponse with Status = "ok"

func PendingResponse

func PendingResponse() StatusResponse

PendingResponse returns StatusResponse with Status = "pending"

Jump to

Keyboard shortcuts

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