common

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2023 License: MPL-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ENV_HOSTNAME               = "HOSTNAME"
	ENV_PREFIX                 = "VAULT_AUTO_UNSEAL"
	ENV_HOST                   = "HOST"
	ENV_PORT                   = "PORT"
	ENV_TLS_CA_CRT_PATH        = "CA_CRT_PATH"
	ENV_TLS_CLIENT_CA_CRT_PATH = "CLIENT_CA_CRT_PATH"
	ENV_TLS_CRT_PATH           = "TLS_CRT_PATH"
	ENV_TLS_KEY_PATH           = "TLS_KEY_PATH"
	ENV_DB_PATH                = "DB_PATH"
	ENV_DB_NAME                = "DB_NAME"
	ENV_LOG_FORMAT             = "LOG_FORMAT"
	ENV_LOG_LEVEL              = "LOG_LEVEL"
	ENV_PRODUCTION             = "PRODUCTION"
)

All currently used ENV VARS Used in the following form: <ENV_PREFIX>_<ENV_VAR>

View Source
const (
	INIT_DB_RES_ERROR   = 0
	INIT_DB_RES_EXISTED = 1
	INIT_DB_RES_CREATED = 2
)
View Source
const (
	VAULT_TOKEN_HEADER = "X-Vault-Token"
	VAULT_TOKEN        = "vaultToken"
	VAULT_TOKEN_MODEL  = "vaultTokenModel"
	SESSION_POLICIES   = "sessionPolicies"
	PATH_CAPABILITIES  = "pathCapabilities"
	IS_ROOT            = "isRoot"
)

Context keys

Variables

This section is empty.

Functions

func Bind

func Bind(c *gin.Context, obj interface{}) error

func CreateDBIfNotExists

func CreateDBIfNotExists(c *Config) (int, error)

Create db file if it doesn't exist

func DecBytesFromB64

func DecBytesFromB64(str string) ([]byte, error)

func DecFromB64

func DecFromB64(str string) (string, error)

func EncToB64

func EncToB64(str string) string

func GetDB

func GetDB() (*gorm.DB, error)

Get DB object

func GetLogger

func GetLogger() (hclog.Logger, error)

Get logger interface

func GetRequestPath

func GetRequestPath(c *gin.Context) string

func JSONMiddleware

func JSONMiddleware(replaceExistingContentType bool) gin.HandlerFunc

func ParseBool

func ParseBool(str string, def bool) bool

Parse Int - parsing integers from strings If error is received during parsing process it'll return the default value

func ParseInt

func ParseInt(str string, def int) int

Parse Int - parsing integers from strings If error is received during parsing process it'll return the default value

func RequestIDMiddleware

func RequestIDMiddleware() gin.HandlerFunc

func TrimPrefix

func TrimPrefix(s string, pref string) string

func VerifyCreateAccess

func VerifyCreateAccess(c *gin.Context) bool

Verify create acces on individual path

func VerifyListAccess

func VerifyListAccess(c *gin.Context) bool

Verify create acces on individual path

Types

type CommonError

type CommonError struct {
	Errors []string `json:"errors"`
}

My own Error type that will help return my customized Error info

{"database": {"hello":"no such table", error: "not_exists"}}

func NewError

func NewError(key string, err error) CommonError

Warp the error info in a object

type Config

type Config struct {
	Lock     sync.RWMutex
	Args     *Params
	TLS      *TLSConfig
	Logger   hclog.Logger
	DBStatus int
	DB       *gorm.DB
}

App Config Struct

func DefaultConfig

func DefaultConfig() (*Config, error)

Init default Config struct

func GetConfig

func GetConfig() (*Config, error)

Return global config

type GenericResponse

type GenericResponse struct {
	RequestID     string       `json:"request_id"`
	LeaseID       string       `json:"lease_id"`
	LeaseDuration int          `json:"lease_duration"`
	Renewable     bool         `json:"renewable"`
	Warnings      *[]string    `json:"warnings"`
	Data          interface{}  `json:"data"`
	WrapInfo      *interface{} `json:"wrap_info"`
	Auth          *interface{} `json:"auth"`
}

func NewGenericResponse

func NewGenericResponse(c *gin.Context, data interface{}) GenericResponse

type GenericResponseSerializer

type GenericResponseSerializer struct {
	C *gin.Context
}

func (*GenericResponseSerializer) Response

func (s *GenericResponseSerializer) Response(data interface{}) GenericResponse

type LogConfig

type LogConfig struct {
	LogFormat string
	LogLevel  string
}

Log specific configuration provided during startup

type Params

type Params struct {
	Host         string
	Port         int
	DBPath       string
	DBName       string
	IsProduction bool
	LogConfig    *LogConfig
}

App params provided during startup This struct is inialized only once, during startup It's should remain unchanged

type StatusResponse

type StatusResponse struct {
	Code   int    `json:"code"`
	Status string `json:"status"`
}

func NewStatusResponse

func NewStatusResponse(code int, status string) StatusResponse

type TLSConfig

type TLSConfig struct {
	TLSConfig *tls.Config
	BundleCrt string
	CACrt     string
	TLSCrt    string
	TLSKey    string
}

TLS conf

Jump to

Keyboard shortcuts

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