vcago

package module
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2020 License: MIT Imports: 15 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 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 added in v0.0.7

func DeleteSession(c echo.Context)

DeleteSession removes session from storage using c.

func GetSession added in v0.0.7

func GetSession(c echo.Context) (apiErr *verr.APIError)

GetSession selects u from the session storage by using c. In case there is no user contains is set false.

func NewSession added in v0.0.7

func NewSession(c echo.Context, user *vmod.User)

NewSession creates a cookie using the `COOKIE_SECURE` and `SAME_SITE` variables from the os environment. For that use .env file in your project. The cookie is always be httpOnly and have a durancy of 7 days. The `user` will be stored in that session as []byte generated with json.Marshal(user).

func SessionAuth added in v0.0.7

func SessionAuth(next echo.HandlerFunc) echo.HandlerFunc

SessionAuth go to next if the request has a session else return 401.

func SessionRedisStore added in v0.0.7

func SessionRedisStore() echo.MiddlewareFunc

SessionRedisStore initial session store via Redis and return session.Middleware. Use with echo framework like echo.Echo.Use(SessionRedisStore())

Types

This section is empty.

Directories

Path Synopsis
api module

Jump to

Keyboard shortcuts

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