fastcontroller

package module
v0.3.14 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2022 License: GPL-3.0 Imports: 11 Imported by: 0

README

fastcontroller

Documentation

Index

Constants

This section is empty.

Variables

View Source
var JwtAlgorithms = map[string]*jwt.SigningMethodHMAC{
	"HS256": jwt.SigningMethodHS256,
	"HS384": jwt.SigningMethodHS384,
	"HS512": jwt.SigningMethodHS512,
}

Functions

func ErrAlreadyExist added in v0.2.0

func ErrAlreadyExist(field string, err error) errorResponseType

func ErrForbiden

func ErrForbiden() errorResponseType

func ErrNotFound

func ErrNotFound(field string, err error) errorResponseType

func ErrNotImplemented

func ErrNotImplemented(fnName string) errorResponseType

func ErrUnauthorized

func ErrUnauthorized(err error) errorResponseType

func ErrValidation

func ErrValidation(message string, err error) errorResponseType

func MakeJWT

func MakeJWT(cfg JWT, id uint, username string, role Role, perms ...Permission) (string, error)

func PermissionExist

func PermissionExist(perm Permission, perms []Permission) bool

Types

type Claims

type Claims struct {
	ID          uint         `json:"id"`
	Username    string       `json:"username"`
	Role        Role         `json:"role"`
	Permissions []Permission `json:"permissions"`
	jwt.StandardClaims
}

func GetClaimsFromJWT

func GetClaimsFromJWT(cfg JWT, token []byte) (*Claims, error)

type Config

type Config struct {
	DevMode   bool
	SecretKey string
	JWT       JWT
	HTTPPort  int
	DbSession SessionConfig
}

type Context

type Context struct {
	*fasthttp.RequestCtx
	Identify *Identify
}

func (Context) ReadUserIP

func (c Context) ReadUserIP() string

func (*Context) WithIdentify

func (c *Context) WithIdentify(id uint, username string, r Role, p ...Permission) *Context

type Controller

type Controller struct {
	Log    logrus.FieldLogger
	Config Config
}

func NewController

func NewController(l logrus.FieldLogger, c Config) Controller

func (Controller) Authorize

func (c Controller) Authorize(f fnAction, r Role, perms ...Permission) fnAction

func (Controller) DecodeJson

func (c Controller) DecodeJson(ctx *Context, v interface{}) error

func (Controller) Handle

func (c Controller) Handle(f fnAction) fasthttp.RequestHandler

func (Controller) HandleW added in v0.3.8

func (c Controller) HandleW(f fnAction) fasthttp.RequestHandler

TODO: fix error handling

func (Controller) Response added in v0.3.0

func (c Controller) Response(ctx *Context, statusCode int) error

func (Controller) ResponseWithJson added in v0.3.13

func (c Controller) ResponseWithJson(ctx *Context, statusCode int, v interface{}) error

func (Controller) SetJWT

func (c Controller) SetJWT(ctx *Context, tkn string)

func (Controller) View

func (c Controller) View(ctx *Context, buff *bytes.Buffer) error

type ErrorResponseType

type ErrorResponseType interface {
	HTTPCode() int
	HTTPMessage() string
	InternalError() error
}

type Identify

type Identify struct {
	Id          uint
	Username    string
	Role        Role
	Permissions []Permission
}

type JWT

type JWT struct {
	Secret       []byte
	Algorithm    jwt.SigningMethod
	MaxAge       int64
	HTTPOnly     bool
	RefreshToken RefreshToken
	Path         string
	Secure       bool
}

type Permission

type Permission uint8
const (
	// NoPermission
	NoPermission Permission = iota
)

type RefreshToken

type RefreshToken struct {
	Secret    []byte
	Algorithm jwt.SigningMethodHMAC
	MaxAge    int64
	Secure    bool
	HTTPOnly  bool
	Path      string
}

type Role

type Role uint8
const (
	NoRole Role = iota
	SuperUserRole
	ServiceRole
	AdminRole
	UserRole
)

type SessionConfig

type SessionConfig struct {
	Driver          string
	Host            string
	Port            string
	User            string
	Password        string
	DBName          string
	Schema          string
	TestDBName      string
	AdminDBName     string
	SslMode         string
	TimeZone        string
	MigrationsPath  string
	MigrationsTable string
}

func (SessionConfig) AdminDsn added in v0.3.14

func (s SessionConfig) AdminDsn() string

func (SessionConfig) Dsn

func (s SessionConfig) Dsn() string

func (SessionConfig) DsnWithSchema

func (s SessionConfig) DsnWithSchema() string

Jump to

Keyboard shortcuts

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