irisx

package module
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2022 License: MIT Imports: 16 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

irisx

extends iris

Installation

go get github.com/daqiancode/irisx

Example

v := irisx.NewVerifier(env.Getenv("jwt_public_key"), jwt.EdDSA)
mvcApp := mvc.New(app).Party(env.Getenv("app_prefix", "/"))
mvcApp.Party("/").Handle(new(controller.PublicController))
mvcApp.Party("/user", v.Middleware(), irisx.NewRbacMiddleware("USER").Middleware).Handle(new(controller.UserController))
mvcApp.Party("/admin/user", v.Middleware(), irisx.NewRbacMiddleware("ADMIN").Middleware).Handle(new(controller.AdminUserController))

Documentation

Index

Constants

This section is empty.

Variables

View Source
var IrisxLog = logger.NewLogger(map[string]string{"src": "irisx"}, true, false)

Functions

func GetJSONSerializer

func GetJSONSerializer() jsoniter.API

func HandleError

func HandleError(err error) commons.Result

func NewRecover added in v0.0.3

func NewRecover(log zerolog.Logger) context.Handler

func OK

func OK(data interface{}) commons.Result

Types

type Contextx

type Contextx struct {
	iris.Context
}

func (*Contextx) Error

func (c *Contextx) Error(err error) error

func (*Contextx) ErrorParam

func (c *Contextx) ErrorParam(err error) error

request parameter error

func (*Contextx) ErrorService

func (c *Contextx) ErrorService(err error) error

bussiness logic error

func (*Contextx) Fail

func (c *Contextx) Fail(message string, state, httpStatus int) error

func (*Contextx) FailInternal added in v0.0.2

func (c *Contextx) FailInternal(message string, state int) error

server internal error

func (*Contextx) FailParams added in v0.0.2

func (c *Contextx) FailParams(fieldErrors map[string]string) error

request parameter error

func (*Contextx) FailService added in v0.0.2

func (c *Contextx) FailService(message string, state int) error

bussiness logic error

func (*Contextx) Finish added in v0.0.4

func (c *Contextx) Finish(data interface{}, err error) error

func (*Contextx) GetIP

func (c *Contextx) GetIP() string

func (*Contextx) GetUID

func (c *Contextx) GetUID() string

func (*Contextx) IsLogined

func (c *Contextx) IsLogined() bool

func (*Contextx) JSON

func (c *Contextx) JSON(v interface{}) error

func (*Contextx) OK

func (c *Contextx) OK(data interface{}) error

func (*Contextx) Page added in v0.0.4

func (c *Contextx) Page(items interface{}, pageIndex, pageSize int, total int64, err error) error

func (*Contextx) ReadForm

func (c *Contextx) ReadForm(formObject interface{}) error

func (*Contextx) ReadJSON

func (c *Contextx) ReadJSON(outPtr interface{}) error

func (*Contextx) ReadQuery

func (c *Contextx) ReadQuery(ptr interface{}) error

type RbacClaims

type RbacClaims struct {
	jwt.Claims
	// roles seperate by space. e.g., "USER ADMIN"
	Roles string `json:"roles,omitempty"`
}

subject(sub) is user id

type RbacMiddleware

type RbacMiddleware struct {
	// contains filtered or unexported fields
}

func NewRbacMiddleware

func NewRbacMiddleware(roles ...string) *RbacMiddleware

func (*RbacMiddleware) Middleware

func (s *RbacMiddleware) Middleware(ctx iris.Context)

type Verifier

type Verifier struct {
	// contains filtered or unexported fields
}

func NewVerifier

func NewVerifier(publicKey string, alg jwt.Alg) *Verifier

NewVerifier please use ECDSA alg

func (*Verifier) GetVerifier

func (v *Verifier) GetVerifier() *jwt.Verifier

func (*Verifier) Middleware

func (v *Verifier) Middleware(validators ...jwt.TokenValidator) context.Handler

func (*Verifier) SetBlockList

func (v *Verifier) SetBlockList(blocklist *redis.Blocklist)

Jump to

Keyboard shortcuts

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