context

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: AGPL-3.0 Imports: 20 Imported by: 0

Documentation

Overview

Package context contains the application context types.

This package only exists to avoid a circular import between app and cli packages, otherwise these types should be in the app package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Context

type Context struct {
	Ctx     context.Context // global context
	FS      vfs.FileSystem  // filesystem
	DataDir string          // app data storage directory
	Env     Environment     // process environment
	Logger  *slog.Logger    // global logger
	UUIDGen func() string   // UUID generator

	// Standard streams
	Stdin  io.Reader
	Stdout io.Writer
	Stderr io.Writer

	// Stores
	DB    *db.DB
	Store store.Store
	User  *models.User // current app user

	// Metadata
	Version     *VersionInfo
	VersionInit string // app version the DB was initialized with
}

Context contains common objects used by the application. It is passed around the application to avoid direct dependencies on external systems, and make testing easier.

func (*Context) LoadLocalUser

func (c *Context) LoadLocalUser(encKey *[32]byte) error

LoadLocalUser loads the local user from the database into c.User, optionally validating the provided encryption key with the stored hash. Note that this *must* load a single user. Currently only a single local user is created, but in the future this might change.

func (*Context) ServerTLSInfo

func (c *Context) ServerTLSInfo() (
	cert *tls.Certificate, certPEM []byte, san string, err error,
)

ServerTLSInfo returns the TLS certificate, private key and Subject Alternative Name used by the server.

type Environment

type Environment interface {
	Get(string) string
	Set(string, string) error
}

Environment is the interface to the process environment.

type VersionInfo

type VersionInfo struct {
	Commit      string
	Semantic    string
	TagDistance int // number of commits since latest tag
	Dirty       bool
	// contains filtered or unexported fields
}

VersionInfo stores app version information.

func GetVersion

func GetVersion() (*VersionInfo, error)

GetVersion returns the app version including VCS and Go runtime information. It first reads the VCS version set at build time, and falls back to the VCS information provided by the Go runtime. The information in the Go runtime is not as extensive as the one extracted from Git, and we use the Go runtime information in case the binary is built without setting -ldflags (e.g. Homebrew), so we still need both. See https://github.com/golang/go/issues/50603

func (*VersionInfo) String

func (vi *VersionInfo) String() string

String returns the full version information.

func (*VersionInfo) UnmarshalText

func (vi *VersionInfo) UnmarshalText(data []byte) error

UnmarshalText parses the output of `git describe`.

Jump to

Keyboard shortcuts

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