filetoken

package
v0.14.1 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultHashedFileName

func DefaultHashedFileName(appKey string) string

DefaultHashedFileName returns "<hash>.json" for appKey.

func DefaultTokenDir

func DefaultTokenDir(cwd string) (string, error)

DefaultTokenDir resolves the default token directory.

func FindProjectRoot

func FindProjectRoot(start string) (string, bool)

FindProjectRoot walks up from start and returns the directory containing go.mod.

func HashAppKey

func HashAppKey(appKey string) string

HashAppKey returns the first 12 chars of sha256(appKey).

func JSONFileOnly

func JSONFileOnly(name string) bool

JSONFileOnly returns true for *.json files.

func PrefixedHashedFileName

func PrefixedHashedFileName(prefix string) func(string) string

PrefixedHashedFileName returns "<prefix><hash>.json" builder.

func PrefixedJSONFileOnly

func PrefixedJSONFileOnly(prefix string) func(string) bool

PrefixedJSONFileOnly returns a file predicate for prefixed *.json files.

Types

type Entry

type Entry struct {
	AccessToken string    `json:"access_token"`
	ExpiresAt   time.Time `json:"expires_at"`
	AppKey      string    `json:"app_key"`
}

Entry represents one cached token record.

type Manager

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

Manager stores tokens in memory and persists them on disk.

func New

func New(opts Options) *Manager

New creates a configured file-backed token manager.

func (*Manager) DeleteToken added in v0.14.0

func (m *Manager) DeleteToken(appKey string) error

DeleteToken removes the cached token for appKey from memory and disk.

func (*Manager) GetToken

func (m *Manager) GetToken(appKey string) (string, time.Time, bool)

GetToken returns a valid cached token for appKey when available.

func (*Manager) SetToken

func (m *Manager) SetToken(appKey, token string, expiresAt time.Time) error

SetToken stores the token in memory and on disk.

func (*Manager) TokenDir

func (m *Manager) TokenDir() (string, error)

TokenDir resolves the directory where token files are stored.

func (*Manager) WaitForAuth

func (m *Manager) WaitForAuth(appKey string)

WaitForAuth enforces per-appKey token issuance throttling.

type Options

type Options struct {
	Dir                 string
	AuthLimiterName     string
	ValidityBuffer      time.Duration
	AllowFileName       func(name string) bool
	BuildFileName       func(appKey string) string
	RequireAppKeyOnLoad bool
}

Options configures a file-backed token manager.

Jump to

Keyboard shortcuts

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