simpletoken

package module
v0.0.0-...-ceb340c Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2019 License: MIT Imports: 10 Imported by: 0

README

Simple Token !

Generating HMAC based token is so easy with simpletoken..

Installation
$ go get -u github.com/ahmdrz/simpletoken
Examples
package main

import (
	"fmt"
	"time"

	"github.com/ahmdrz/simpletoken"
)

type Payload struct {
	Username  string
	CreatedAt time.Time
}

func main() {
	simpleToken, err := simpletoken.New("md5", []byte("long-long-secret-key"))
	if err != nil {
		panic(err)
	}

	myPayload := Payload{
		Username:  "ahmdrz",
		CreatedAt: time.Now(),
	}
	token, err := simpleToken.Generate(myPayload)
	if err != nil {
		panic(err)
	}

	fmt.Printf("token is %s\n", token)

	output := Payload{}
	err = simpleToken.ParseString(token.String(), &output)
	if err != nil {
		panic(err)
	}

	fmt.Printf("payload is %v\n", output)
}

Find expirableToken example in example directory.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type SimpleToken

type SimpleToken struct {
	// contains filtered or unexported fields
}

func New

func New(algorithm string, secret []byte) (*SimpleToken, error)

func (*SimpleToken) Generate

func (s *SimpleToken) Generate(payload interface{}) (*Token, error)

func (*SimpleToken) Parse

func (s *SimpleToken) Parse(token []byte, output interface{}) error

func (*SimpleToken) ParseString

func (s *SimpleToken) ParseString(token string, output interface{}) error

type Token

type Token struct {
	// contains filtered or unexported fields
}

func (*Token) Bytes

func (t *Token) Bytes() []byte

func (*Token) String

func (t *Token) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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