helpers

package
v0.0.0-...-10bc8b7 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2023 License: MIT Imports: 31 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	CryptoMethods = &crytoMethods{
		BCrypt: BCryptMethod,
		SCrypt: SCryptMethod,
	}
)

CryptoMethods kind a enum for cryptography methods supported

View Source
var DefaultPageSize int = 100

DefaultPageSize default page size

Functions

func AllIn

func AllIn(in, all []string) bool

AllIn are all elements of and array inside another array

func BsonQuote

func BsonQuote(s string) string

BsonQuote quote a string

func BsonQuoteMap

func BsonQuoteMap(m *map[string]interface{}) map[string]interface{}

BsonQuoteMap create a new map of quotes with escaped indexes

func BsonUnquote

func BsonUnquote(s string) string

BsonUnquote unquote a string

func BsonUnquoteMap

func BsonUnquoteMap(m *map[string]interface{}) map[string]interface{}

BsonUnquoteMap create a new map of quotes with unescaped indexes

func CheckPasswordHash

func CheckPasswordHash(password, hash string, method Method) bool

CheckPasswordHash validate password agains a given hash

func CreateAccountToken

func CreateAccountToken(acc *authmodels.Account, scopes []string) (*authmodels.TokenPayload, error)

CreateAccountToken create account token

func CreateAuthenticityToken

func CreateAuthenticityToken() (string, error)

CreateAuthenticityToken create authenticity token for forms

func Fetch

func Fetch(ctx context.Context, method, url string, content []byte, rp interface{}, headers map[string]string, queries map[string]string) ([]byte, error)

Fetch do an http request

func FilterStrings

func FilterStrings(arr []string, cond func(string) bool) []string

FilterStrings filter and slice of strings

func FlatMap

func FlatMap(i interface{}, prefix string) map[string]string

FlatMap flat a map structure

func GetEnv

func GetEnv(key, defaultValue string) string

GetEnv return values of the environment

func GetFormat

func GetFormat(c string) string

func GetJWTConfig

func GetJWTConfig() middleware.JWTConfig

GetJWTConfig return jwt config

func GetMongoFieldsFromQuery

func GetMongoFieldsFromQuery(querystring url.Values) bson.M

GetMongoFieldsFromQuery get mongo fields from query

func GetMongoPaginationFromQuery

func GetMongoPaginationFromQuery(querystring url.Values) bson.M

GetMongoPaginationFromQuery get mongo pagination from query

func GetMongoQueryFromQuery

func GetMongoQueryFromQuery(querystring url.Values) bson.M

GetMongoQueryFromQuery get mongo query from url query

func GetMongoSortingFromQuery

func GetMongoSortingFromQuery(querystring url.Values) bson.M

GetMongoSortingFromQuery get mongo sorting from query

func GetPaginationLink(u url.URL, total int64, last, first helpermodels.Datable) helpermodels.Pagination

GetPaginationLink get pagination link

func HashPassword

func HashPassword(password string, method Method) (string, error)

HashPassword create a hashed version of a string

func IsNotEmptyString

func IsNotEmptyString(value string) bool

IsNotEmptyString check if an string is not empty

func MergeMaps

func MergeMaps(left, right map[string]interface{}) map[string]interface{}

MergeMaps Given two maps, recursively merge right into left, NEVER replacing any key that already exists in left

func NotImplemented

func NotImplemented(c echo.Context) error

NotImplemented rest handler not implemented

func ParseDuration

func ParseDuration(str string, defaultDuration time.Duration) time.Duration

ParseDuration parse a duration string

func ParseDurationToString

func ParseDurationToString(duration time.Duration) string

ParseDurationToString parse a duration string

func ParseInt64

func ParseInt64(value string) int64

ParseInt64 parse string into int64

func SetMongoPagination

func SetMongoPagination(q, s, pa map[string]interface{}, queryOptions *options.FindOptions)

SetMongoPagination set pagination

func SetupEnvDefaults

func SetupEnvDefaults()

SetupEnvDefaults : Initialize EnvDefaults

func ValidateAuthenticityToken

func ValidateAuthenticityToken(tokenString string) error

ValidateAuthenticityToken validate authenticity token for forms

Types

type ApiSearchPagination

type ApiSearchPagination struct {
	Filters    bson.M
	Sort       bson.M
	Fields     bson.M
	Pagination bson.M
}

type EnvDefaults

type EnvDefaults struct {
	// ServerHost api server host
	ServerHost string

	// ServerPort api server port
	ServerPort string

	// HostURL api host URL
	HostURL string

	// SessionSecret secret key for session cookie
	SessionSecret string

	// JWTTimeoutMinutes JWT timeout
	JWTTimeoutMinutes string

	// JWTAuthSecret JWT timeout
	JWTAuthSecret *rsa.PrivateKey

	// JWTSigningSecret secret word to sign jwt tokens
	JWTSigningSecret string

	// AuthenticityTokenTTLMinutes authenticity token time to live in minutes
	AuthenticityTokenTTLMinutes string

	// ScryptSecret secret key for scrypt hash of passwords
	ScryptSecret string

	// CronConfig cron initial configuration
	CronConfig string

	// FluentHost fluentd host
	FluentHost string

	// FluentPort fluentd port
	FluentPort string

	// ElasticURL elastic search url
	ElasticURL string

	// ElasticUsername elastic search server username
	ElasticUsername string

	// ElasticPassword elastic search server password
	ElasticPassword string

	// ElasticBearer elastic search server token
	ElasticBearer string

	// CollectionPrefix database collection prefix to all collections
	CollectionPrefix string

	OpaClientUrl    string
	OpaAppName      string
	SpiceDBURL      string
	SpiceDBToken    string
	SpiceDBInsecure string
}

EnvDefaults : EnvDefaults Structure to hold Env default Variable values

var Env EnvDefaults

Env : Env variable to hold Env default Variable values

type JwtRsaKeys

type JwtRsaKeys struct {
	PrivateKey *rsa.PrivateKey
	PublicKey  *rsa.PublicKey
}

JwtRsaKeys Public and Private keys for Jwt

type Method

type Method string

Method define methods for encrypt supported

const (
	// BCryptMethod method
	BCryptMethod Method = "bcrypt"
	// SCryptMethod method
	SCryptMethod Method = "scrypt"
)

type RestHTTPError

type RestHTTPError struct {
	Code     int         `json:"-"`
	Message  interface{} `json:"message"`
	Internal error       `json:"-"` // Stores the error returned by an external dependency
}

RestHTTPError rest http

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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