utils

package
v0.0.0-...-b8d8853 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2024 License: Apache-2.0 Imports: 35 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CaptureErrors

func CaptureErrors(handler http.Handler) http.Handler

func CheckPassword

func CheckPassword(hashedPassword, password string) bool

func CommonHandler

func CommonHandler(w http.ResponseWriter, r *http.Request, msg string, logic HandlerFunc)

commonHandler is a function that handles common logic for HTTP handlers.

func CommonJsonHandler

func CommonJsonHandler(r *http.Request, logic HandlerFunc) (interface{}, *ec.Error)

func CorsMiddleware

func CorsMiddleware(next http.Handler) http.Handler

func DebugTest

func DebugTest(t *testing.T, data interface{}, name string)

func EnableCors

func EnableCors(w *http.ResponseWriter)

func GetHost

func GetHost(r *http.Request) string

func GetJWTKey

func GetJWTKey() []byte

func HashPassword

func HashPassword(password string) (string, error)

func HashStr

func HashStr(v string) string

func InitializeAppKey

func InitializeAppKey(appKey string)

func InitializeSentry

func InitializeSentry(dsn string)

func KeyByRealIP

func KeyByRealIP(r *http.Request) (string, error)

KeyByRealIP copied from httprate.KeyByRealIP this is to fully support other platforms, especially CF-Connecting-IP

func LogRequest

func LogRequest(next http.Handler) http.Handler

func Logger

func Logger() *zerolog.Logger

func RateLimit

func RateLimit(rateLimit int) func(http.Handler) http.Handler

func RejectNonSpecificDomain

func RejectNonSpecificDomain(domain string) func(next http.Handler) http.Handler

func RequireApiKeyMiddleware

func RequireApiKeyMiddleware(next http.Handler) http.Handler

func RequireJWTAuthMiddleware

func RequireJWTAuthMiddleware(next http.Handler) http.Handler

func SetDefaultMiddlewares

func SetDefaultMiddlewares(r *chi.Mux)

func Validator

func Validator() *validator.Validate

func WebFirewallMiddleware

func WebFirewallMiddleware(next http.Handler) http.Handler

Types

type Claims

type Claims struct {
	UserID string `json:"user_id"`
	jwt.RegisteredClaims
}

func CreateJwtClaims

func CreateJwtClaims(userID string, expTime time.Time, subject string) *Claims

type ContextKey

type ContextKey string

func (ContextKey) String

func (c ContextKey) String() string

type Crypt

type Crypt struct {
	Key string
}

func NewCrypt

func NewCrypt() *Crypt

func NewCryptWithKey

func NewCryptWithKey(key string) *Crypt

func (*Crypt) Decrypt

func (c *Crypt) Decrypt(value string) (string, error)

Decrypt takes an encrypted value and a key, both of type string, and returns the decrypted value as a string. It uses AES CBC decryption with PKCS7 padding.

func (*Crypt) Encrypt

func (c *Crypt) Encrypt(value string) (string, error)

Encrypt takes a value and a key, both of type string, and returns the encrypted value as a string. It uses AES CBC encryption with PKCS7 padding.

type ErrorStatus

type ErrorStatus struct {
	Error   error
	Message string
	Status  int
}

type HandlerFunc

type HandlerFunc func([]byte) (interface{}, *ec.Error)

HandlerFunc is a type that defines a function that takes a byte slice and returns an interface and an error.

type Response

type Response struct {
	Success bool        `json:"success"`
	Message string      `json:"message"`
	Data    interface{} `json:"data"`
	// contains filtered or unexported fields
}

func NewResponse

func NewResponse(w http.ResponseWriter) *Response

func (*Response) HandleErrorCode

func (r *Response) HandleErrorCode(errc *ec.Error)

func (*Response) WriteErrorResponse

func (r *Response) WriteErrorResponse(message string, statusCode int)

func (*Response) WriteSuccessResponse

func (r *Response) WriteSuccessResponse(message string, data interface{})

func (*Response) WriteValidationError

func (r *Response) WriteValidationError(errc *ec.Error) bool

func (*Response) WriteValidationResponse

func (r *Response) WriteValidationResponse(message string, data interface{})

Jump to

Keyboard shortcuts

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