token

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2023 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrMissingHeader means the `Authorization` header was empty.
	ErrMissingHeader = errors.New("the length of the `Authorization` header is zero")
	// ErrMissingToken means the `token` params was empty.
	ErrMissingToken = errors.New("missing token")
)

Functions

func Sign

func Sign(ctx *gin.Context, c Context, secret string) (tokenString string, err error)

Sign signs the context with the specified secret.

Types

type Context

type Context struct {
	ID       uint64
	Username string
}

Context is the context of the JSON view token.

func Parse

func Parse(tokenString string, secret string) (*Context, error)

Parse validates the token with the specified secret, and returns the context if the token was valid.

func ParseRequest

func ParseRequest(c *gin.Context) (*Context, error)

ParseRequest gets the token from the header and pass it to the Parse function to parses the token.

func ParseToken

func ParseToken(t string) (*Context, error)

ParseToken directly parse the token

Jump to

Keyboard shortcuts

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