fst

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2023 License: MIT Imports: 11 Imported by: 0

README

fst

fst is a high-performance, low-memory library for generating and parsing Fast Signed Tokens (FST). FST provides an alternative to JSON-based tokens and allows you to store any information that can be represented as []byte. You can use FST for the same purposes as JWT.

Description

fst is designed to be efficient and lightweight, making it ideal for applications that require fast token generation and parsing. With its optimized algorithms and data structures, fst minimizes memory usage and maximizes performance.

Performance

fst excels in terms of performance, especially when compared to traditional token formats like JSON Web Tokens (JWT). By leveraging its unique token structure and optimized parsing algorithms, fst significantly reduces the overhead associated with token generation and parsing.

To demonstrate the performance benefits of fst, we conducted a series of tests using various tokens sizes. The results are as follows:

parsing speed (less is better):

Image Description

generate speed (less is better):

Image Description

parsing memory (less is better): Image Description

generate memory (less is better): Image Description

parallel parsing speed (less is better): Image Description

parallel generate speed (less is better): Image Description

Installation

Install fst with the go get command:

go get github.com/Eugene-Usachev/fst

Example

You can see the examples in the example folder.

First you need to create a `Converter'. You can do it like this

converter := fst.NewConverter(&fst.ConverterConfig{
    SecretKey:   []byte(`secret`),
    Postfix:     nil,
    ExpireTime:  time.Minute * 5,
    HashType:    sha256.New,
    DisableLogs: false,
})

Then you can create a token using the NewToken or NewTokenWithExpire functions.

token := converter.NewToken([]byte(`token`))
// or create token with set expire time
tokenWithEx := converter.NewTokenWithExpire([]byte(`token`))

To parse tokens, you can use the ParseToken or ParseTokenWithExpire functions.

value, err := converter.ParseToken(token)
// or parse token with set an expiry time
value, err = converter.ParseTokenWithExpire(tokenWithEx)

License

The fst library is released under the MIT License.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Converter

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

func NewConverter

func NewConverter(cfg *ConverterConfig) *Converter

func (*Converter) ExpireTime

func (c *Converter) ExpireTime() time.Duration

func (*Converter) NewToken

func (c *Converter) NewToken(value []byte) string

func (*Converter) NewTokenWithExpire

func (c *Converter) NewTokenWithExpire(value []byte) string

func (*Converter) ParseToken

func (c *Converter) ParseToken(token string) ([]byte, error)

func (*Converter) ParseTokenWithExpire

func (c *Converter) ParseTokenWithExpire(token string) ([]byte, error)

func (*Converter) Postfix

func (c *Converter) Postfix() []byte

func (*Converter) SecretKey

func (c *Converter) SecretKey() []byte

type ConverterConfig

type ConverterConfig struct {
	SecretKey  []byte
	Postfix    []byte
	ExpireTime time.Duration
	HashType   func() hash.Hash

	DisableLogs bool
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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