server

package
v0.0.0-...-89bec85 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2023 License: MIT Imports: 17 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Jwtware = jwtware.New(jwtware.Config{
	SigningKey:    []byte(constant.JWT_SECRET),
	ContextKey:    constant.JWT_CONTEXT,
	SigningMethod: "HS256",
	TokenLookup:   "header:Authorization,cookie:token",
	ErrorHandler: func(c *fiber.Ctx, err error) error {
		if err.Error() == "Missing or malformed JWT" {
			return c.Status(fiber.StatusBadRequest).SendString("无效的token信息")
		} else {
			return c.Status(fiber.StatusUnauthorized).SendString("Invalid or expired Authorization Token")
		}
	},
	SuccessHandler: func(c *fiber.Ctx) error {

		jwtToken := c.Locals(constant.JWT_CONTEXT).(*jwt.Token)
		claims := jwtToken.Claims.(jwt.MapClaims)
		uid := claims["uid"].(string)
		sid := claims["sid"].(string)
		tenantId, tenantOk := claims["tenantId"].(string)

		if cache.Enabled() {
			rConn := cache.Get()
			defer rConn.Close()
			cachedUid, err := redis.String(rConn.Do("GET", cache.Prefix+":"+constant.AppSid+":"+sid))
			if err != nil {
				if err != redis.ErrNil {
					logger.Error(err)
				}
				return c.Status(fiber.StatusUnauthorized).SendString("token信息失效")
			}
			if cachedUid != uid {
				logger.Error(err)
				return c.Status(fiber.StatusUnauthorized).SendString("token信息失效")
			}
		}

		c.Locals("userId", uid)
		if tenantOk {
			c.Locals("tenantId", tenantId)
		}
		return c.Next()
	},
})

Functions

func All

func All(path string, handlers ...fiber.Handler) fiber.Router

func Delete

func Delete(path string, handlers ...fiber.Handler) fiber.Router

func Get

func Get(path string, handlers ...fiber.Handler) fiber.Router

func GetClientIp

func GetClientIp(ctx *fiber.Ctx) string

func Group

func Group(prefix string, needLogin, needRouterPermission bool) fiber.Router

func InitWebApp

func InitWebApp(views fiber.Views) *webApp

func Listener

func Listener(ln net.Listener) error

func NoNeed

func NoNeed(ctx *fiber.Ctx) error

func ParsePaginationInfoFromQuery

func ParsePaginationInfoFromQuery(ctx *fiber.Ctx) (limit, offset int, orderBy string, err error)

func Post

func Post(path string, handlers ...fiber.Handler) fiber.Router

func Put

func Put(path string, handlers ...fiber.Handler) fiber.Router

func RequireRouterPermission

func RequireRouterPermission() fiber.Handler

func Shutdown

func Shutdown() error

func StandardRouter

func StandardRouter(prefix string, add, update, delete, get, paginate fiber.Handler) fiber.Router

StandardRouter 标准路由,需要登录、校验权限

func StandardVersionRouter

func StandardVersionRouter(version, prefix string, add, update, delete, get, paginate fiber.Handler) fiber.Router

func Start

func Start(addr string) error

func Static

func Static(dir string)

func Use

func Use(args ...interface{}) fiber.Router

Types

This section is empty.

Jump to

Keyboard shortcuts

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