admin

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: May 24, 2019 License: MIT Imports: 5 Imported by: 0

README

Staffio client for gin

Example

package main

import (
	"net/http"

	"github.com/gin-gonic/gin"
	staffiogin "github.com/liut/staffio/client/gin"
)

func main() {

	router := gin.Default()
	loginPath := "/auth/login"
	staffiogin.SetLoginPath(loginPath)
	staffiogin.SetAdminPath("/admin")

	router.GET(loginPath, staffiogin.LoginHandler)
	router.GET("/auth/callback", staffiogin.AuthCodeCallback("admin"))

	adminGroup := router.Group("/admin", staffiogin.AuthMiddleware(true)) // auto redirect
	adminGroup.GET("/", handlerAdminWelcome)
	...

	apiGroup := router.Group("/api", AuthMiddleware(false)) // don't redirect
	apiGroup.GET("/me", staffiogin.HandlerShowMe)
	...

}

func handlerAdminWelcome(c *gin.Context) {
	user, _ := staffiogin.UserWithContext(c)
	...
}

Documentation

Index

Constants

View Source
const (
	KeyOper = "oper"
)

Variables

View Source
var (
	LoginHandler = gin.WrapF(staffio.LoginHandler)
	SetLoginPath = staffio.SetLoginPath
	SetAdminPath = staffio.SetAdminPath
)

Functions

func AuthCodeCallback

func AuthCodeCallback(roleName ...string) gin.HandlerFunc

AuthCodeCallback Handler for Check auth with role[s] when auth-code callback

func AuthMiddleware

func AuthMiddleware(redirect bool) gin.HandlerFunc

func HandlerShowMe

func HandlerShowMe(c *gin.Context)

Types

type User

type User = staffio.User

func UserFromContext added in v0.8.2

func UserFromContext(c *gin.Context) (user *User, ok bool)

Jump to

Keyboard shortcuts

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