vcago

package module
v0.1.10 Latest Latest
Warning

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

Go to latest
Published: May 12, 2021 License: MIT Imports: 12 Imported by: 1

README

vca-go

Package for handling vca-api

vcago package

CONSTANTS

const (
	colorRed    = "\033[31m"
	colorGreen  = "\033[32m"
	colorYellow = "\033[33m"
	colorBlue   = "\033[34m"
	colorPurple = "\033[35m"
	colorCyan   = "\033[36m"
	colorWhite  = "\033[37m"
)

VARIABLES

var CORSConfig = middleware.CORSWithConfig(middleware.CORSConfig{
	AllowOrigins:     strings.Split(os.Getenv("ALLOW_ORIGINS"), ","),
	AllowHeaders:     []string{echo.HeaderOrigin, echo.HeaderContentType, echo.HeaderAccept},
	AllowCredentials: true,
})
    CORSConfig for api services. Can be configured via .env.


FUNCTIONS

func DeleteSession(c echo.Context)
    DeleteSession remove sessin for context c from Redis.

func GetSessionUser(c echo.Context) (u *vmod.User, contains bool)
    GetSessionUser return user for c or false if c has no user in Redis

func InitSession(c echo.Context, user *vmod.User)
    InitSession initial a session for a vmod.User via Redis

func JSONErrorHandler(c echo.Context, i interface{}) (rErr *verr.ResponseError)
    JSONErrorHandler formats JsonError to ResponseError

func LogAPIError(e *verr.ApiError, c echo.Context, i interface{})
    LogApiError via log.Print

func RedisSession() echo.MiddlewareFunc
    RedisSession middleware initial redis store for session handling

func ResponseErrorHandler(c echo.Context, apiErr *verr.ApiError, i interface{}) (rErr *verr.ResponseError)
    ResponseErrorHandler handles ApiError

func SessionAuth(next echo.HandlerFunc) echo.HandlerFunc
    SessionAuth go to next if the request has a session else return 401.

func formatRequestPrint(r *http.Request) string

TYPES

type Validator struct {
	Validator *validator.Validate
}
    Validator represents a Json validator

func (cv *Validator) Validate(i interface{}) error
    Validate interface i

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AccessCookieConfig = middleware.JWTConfig{
	Claims:      &vmod.AccessToken{},
	ContextKey:  "token",
	TokenLookup: "cookie:access_token",
	SigningKey:  []byte(os.Getenv("JWT_SECRET")),
}

AccessCookieConfig can with echo for middleware.JWTWithConfig(vmod.AccessConfig) to handling access controll The token is reachable with c.Get("token")

View Source
var HTTPBaseCookie http.Cookie

HTTPBaseCookie defines the base cookie setup for vcago

View Source
var RefreshCookieConfig = middleware.JWTConfig{
	Claims:      &vmod.RefreshToken{},
	ContextKey:  "token",
	TokenLookup: "cookie:refresh_token",
	SigningKey:  []byte(os.Getenv("JWT_SECRET")),
}

RefreshCookieConfig can with echo for middleware.JWTWithConfig(vmod.AccessConfig) to handling access controll The token is reachable with c.Get("token")

View Source
var SessionOptions = new(sessions.Options)

SessionOptions used for user session

Functions

func Env added in v0.1.6

func Env()

Env load the environment variables for vcago

func JWTNewAccessCookie added in v0.1.6

func JWTNewAccessCookie(token *vmod.JWTToken) *http.Cookie

JWTNewAccessCookie create a new http.Cookie contains the access_token.

func JWTNewRefreshCookie added in v0.1.6

func JWTNewRefreshCookie(token *vmod.JWTToken) *http.Cookie

JWTNewRefreshCookie create a new http.Cookie contains the refresh_token.

func JWTUser added in v0.1.10

func JWTUser(c echo.Context) (u *vmod.User)

func NewCORSConfig added in v0.1.0

func NewCORSConfig() middleware.CORSConfig

NewCORSConfig create a echo middleware for cors handling.

func SessionLoadEnv added in v0.1.1

func SessionLoadEnv()

SessionLoadEnv loads session

func SessionWithID added in v0.1.1

func SessionWithID(next echo.HandlerFunc) echo.HandlerFunc

SessionWithID return session wir id

Types

type JWTMiddleware added in v0.1.6

type JWTMiddleware struct {
	RequestCount uint64 `json:"request_count"`
	Scope        string `json:"scope"`
}

JWTMiddleware handles authentication by jwt

type LoadEnv added in v0.1.1

type LoadEnv []bool

LoadEnv used for loading environment variables.

func (LoadEnv) GetEnvBool added in v0.1.1

func (l LoadEnv) GetEnvBool(key string, lvl string, dVal bool) (bool, LoadEnv)

GetEnvBool load a key from environment variables as bool.

func (LoadEnv) GetEnvInt added in v0.1.1

func (l LoadEnv) GetEnvInt(key string, lvl string, dVal int) (int, LoadEnv)

GetEnvInt loads a key from enviroment variables as int. The lvl param defines the log level. For warnings set "w" and for error set "e". If the variable is not used or can be ignored use n for do nothing. The default value can be set by the dVal param.

func (LoadEnv) GetEnvString added in v0.1.1

func (l LoadEnv) GetEnvString(key string, lvl string, dVal string) (string, LoadEnv)

GetEnvString loads a key from enviroment variables as string. The lvl param defines the log level. For warnings set "w" and for error set "e". If the variable is not used or can be ignored use n for do nothing. The default value can be set by the dVal param.

func (LoadEnv) GetEnvStringList added in v0.1.1

func (l LoadEnv) GetEnvStringList(key string, lvl string, dVal []string) ([]string, LoadEnv)

GetEnvStringList as

func (LoadEnv) Validate added in v0.1.1

func (l LoadEnv) Validate()

Validate check if LoadEnv is valid and log.Fatal if on entry is false.

Directories

Path Synopsis
api module

Jump to

Keyboard shortcuts

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