Back to

Package token

Latest Go to latest

The latest major version is .

Published: Oct 12, 2017 | License: MIT | Module:



var (
	// ErrMissingHeader means the `Authorization` header was empty.
	ErrMissingHeader = errors.New("The length of the `Authorization` header is zero.")

func Sign

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

Sign signs the context with the specified secret.

type Context

type Context struct {
	ID       int
	Username string

Context is the context of the JSON web 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.

Package Files

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier