apikey

package module
v0.0.0-...-016e9aa Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2024 License: MIT Imports: 7 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

prefixed-api-key

Go Doc go report card github actions status

Go implementation of seamapi/prefixed-api-key.

Usage

go get github.com/joemiller/prefixed-api-key
package main

import (
	"log"

	apikey "github.com/joemiller/prefixed-api-key"
)

func main() {
	generator, err := apikey.NewGenerator("mycompany")
	if err != nil {
		log.Fatal(err)
	}

	key, err := generator.GenerateAPIKey()
	log.Println(key.Token())

	ok, err := apikey.CheckAPIKey(key.Token(), key.LongTokenHash())
	if err != nil {
		log.Fatal(err)
	}
	if ok {
		log.Println("token matches hash")
	}

	key, err = apikey.ParseAPIKey("mycompany_5TJMbnP3thd_DjzvCr9MQLaKcaMisJuyUntS7Jpk61ZMp")
	log.Println(key.LongTokenHash())
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckAPIKey

func CheckAPIKey(token string, expectedLongTokenHash string) (bool, error)

Types

type Generator

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

func NewGenerator

func NewGenerator(keyPrefix string, opts ...Option) (*Generator, error)

func (*Generator) GenerateAPIKey

func (g *Generator) GenerateAPIKey() (Key, error)

type Key

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

func ParseAPIKey

func ParseAPIKey(token string) (Key, error)

func (Key) LongToken

func (k Key) LongToken() string

func (Key) LongTokenHash

func (k Key) LongTokenHash() string

func (Key) ShortToken

func (k Key) ShortToken() string

func (Key) Token

func (k Key) Token() string

type Option

type Option func(*Generator) error

func WithLongTokenLength

func WithLongTokenLength(n int) Option

func WithShortTokenLength

func WithShortTokenLength(n int) Option

func WithShortTokenPrefix

func WithShortTokenPrefix(key string) Option

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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