Categorygithub.com/go-zoox/connect-middleware-for-gin
modulepackage
1.2.0
Repository: https://github.com/go-zoox/connect-middleware-for-gin.git
Documentation: pkg.go.dev

# README

Connect Middleware for Gin

PkgGoDev Build Status Go Report Card Coverage Status GitHub issues Release

Installation

To install the package, run:

go get github.com/go-zoox/connect-middleware-for-gin

Getting Started

package main

import (
	"github.com/gin-gonic/gin"
	"github.com/go-zoox/connect-middleware-for-gin"
)

func main() {
	r := gin.Default()
	
	r.Use(connect.Create("YOUR_SECRET_KEY"))

	r.GET("/user", func(c *gin.Context) {
		user, err := connect.GetUser(c)
		if err != nil {
			c.JSON(401, gin.H{
				"message": "unauthorized",
			})
			return
		}

		c.JSON(200, gin.H{
			"user": user,
		})
	})

	r.GET("/", func(c *gin.Context) {
		c.JSON(200, gin.H{
			"message": "helloworld",
		})
	})

	r.Run() // 监听并在 0.0.0.0:8080 上启动服务
}

Related Projects

License

GoZoox is released under the MIT License.

# Packages

No description provided by the author

# Functions

Create creates a connect middleware for gin.
GetToken get user from context.
GetUser gets the user from the context.
MustGetToken get user from context.
MustGetUser get user from context.

# Constants

ContextUserKey is the key for the user in the context.

# Variables

Version is the current version of the package.

# Structs

CreateOptions is the options for the Create middleware.