snips

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FileTypeBinary   = "binary"
	FileTypeMarkdown = "markdown"
)
View Source
const (
	// APIKeyTokenPrefix prefixes every minted token so keys are recognizable
	// (and grep-able) in configs and secret scanners.
	APIKeyTokenPrefix = "snips_"
)
View Source
const (
	// NameMaxLength is the maximum length of a file's name.
	NameMaxLength = 40
)

Variables

View Source
var (
	ErrInvalidName = fmt.Errorf("names must be 1-%d alphanumeric characters (hyphen, dot, or underscore separators allowed)", NameMaxLength)
)

Functions

func DecodeContent added in v0.13.0

func DecodeContent(content []byte) ([]byte, error)

func EncodeContent added in v0.13.0

func EncodeContent(content []byte, compress bool) ([]byte, error)

func HashAPIKeyToken added in v0.13.0

func HashAPIKeyToken(token string) string

HashAPIKeyToken returns the hex-encoded SHA-384 digest of a token, the only form in which tokens are stored.

A fast hash is deliberate: unlike a password, a 256-bit random token can't be brute forced, and lookups stay indexable.

func IsZSTDCompressed added in v0.10.0

func IsZSTDCompressed(data []byte) bool

IsZSTDCompressed checks if the data starts with the zstd magic number. https://github.com/facebook/zstd/blob/dev/doc/zstd_compression_format.md#zstandard-frames

func NewAPIKeyToken added in v0.13.0

func NewAPIKeyToken() (token string, hash string, err error)

NewAPIKeyToken mints a new random API token and returns it alongside the hash to persist.

func NormalizeName added in v0.12.0

func NormalizeName(name string) (string, error)

Types

type APIKey added in v0.13.0

type APIKey struct {
	ID         string
	CreatedAt  time.Time
	UpdatedAt  time.Time
	Name       string
	TokenHash  string
	UserID     string
	LastUsedAt *time.Time
	ExpiresAt  *time.Time // nil = never expires
}

APIKey grants REST API access as a user. Only a hash of the token is stored; the token itself is shown once at mint time.

func (*APIKey) DisplayName added in v0.13.0

func (k *APIKey) DisplayName() string

DisplayName returns the key's name, falling back to its ID when unnamed.

func (*APIKey) IsExpired added in v0.13.0

func (k *APIKey) IsExpired() bool

IsExpired reports whether the key's optional expiry has passed. Expired keys are rejected for authentication but kept (and listed) until removed.

type File

type File struct {
	ID        string    `json:"id"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
	Size      uint64    `json:"size"`
	Private   bool      `json:"private"`
	Type      string    `json:"type"`
	UserID    string    `json:"-"`
	Name      string    `json:"name,omitempty"`
}

func (*File) DisplayName added in v0.12.0

func (f *File) DisplayName() string

func (*File) GetSignedURL

func (f *File) GetSignedURL(cfg *config.Config, ttl time.Duration) (url.URL, time.Time)

func (*File) IsBinary

func (f *File) IsBinary() bool

func (*File) IsMarkdown

func (f *File) IsMarkdown() bool

func (*File) Visibility

func (f *File) Visibility() string

type PublicKey

type PublicKey struct {
	ID          string
	CreatedAt   time.Time
	UpdatedAt   time.Time
	Fingerprint string
	Type        string
	UserID      string
}

type Revision added in v0.10.0

type Revision struct {
	ID        string    `json:"id"`
	Sequence  int64     `json:"sequence"`
	FileID    string    `json:"-"`
	CreatedAt time.Time `json:"created_at"`
	Size      uint64    `json:"size"` // file size after this revision
	Type      string    `json:"type"` // file type after this revision
}

type User

type User struct {
	ID         string    `json:"id"`
	CreatedAt  time.Time `json:"created_at"`
	UpdatedAt  time.Time `json:"updated_at"`
	ThemeColor string    `json:"-"`
}

Jump to

Keyboard shortcuts

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