Documentation ΒΆ
Index ΒΆ
- Constants
- Variables
- func EnvVarOrBool(key string, def bool) bool
- func EnvVarOrDuration(key string, def time.Duration) time.Duration
- func EnvVarOrInt(key string, def int) int
- func EnvVarOrLogLevel(key string, def slog.Level) slog.Level
- func EnvVarOrString(key, def string) string
- func EnvVarOrURL(key, def string) *url.URL
- func NewAppPropsContext(ctx context.Context, props AppProps) context.Context
- func NewLogLevel(val string) slog.Level
- type AccessState
- type Account
- type AppProps
- type DeletedTime
- type Environment
- func (e Environment) CanUseServiceStub() bool
- func (e Environment) IsDemo() bool
- func (e Environment) IsDevelopment() bool
- func (e Environment) IsProduction() bool
- func (e Environment) IsReview() bool
- func (e Environment) IsStaging() bool
- func (e Environment) IsTesting() bool
- func (e Environment) String() string
- func (e Environment) ToolboxEnabled() bool
- func (e Environment) Valid() error
- type Key
- type Model
- type Tool
- type ToolAction
- type Toolbox
- type User
Constants ΒΆ
const ( LogKindKey = "kind" LogMaskVal = "xxxxxx" )
Variables ΒΆ
var ( ErrBadConfig = errors.New("bad config") ErrMissingData = errors.New("missing data") ErrNotExist = errors.New("not exist") ErrNotValid = errors.New("invalid") )
var ( AppLogKind = slog.StringValue("app") HTTPLogKind = slog.StringValue("http") WorkerLogKind = slog.StringValue("worker") // MaskedLogValue is a convenience [golang.org/x/exp/slog.Value] // to be used in implementations of [golang.org/x/exp/slog.LogValuer] // to hide sensitive data from log messages. MaskedLogValue = slog.StringValue(LogMaskVal) )
Functions ΒΆ
func EnvVarOrBool ΒΆ added in v0.6.0
EnvVarOrBool gets the environment variable for the provided key and returns whether it matches "true" or "false" (after lower casing it) or the default value.
func EnvVarOrDuration ΒΆ added in v0.6.0
EnvVarOrDuration gets the environment variable for the provided key, parses it into a time.Duration, or, returns the default time.Duration.
func EnvVarOrInt ΒΆ added in v0.6.1
EnvVarOrInt gets the environment variable for the provided key, creates an int from the retrieved value, or returns the provided default if the value is not a valid int.
func EnvVarOrLogLevel ΒΆ added in v0.6.0
EnvVarOrLogLevel gets the environment variable for the provided key, creates a log/slog.Level from the retrieved value, or returns the provided default log/slog.Level.
func EnvVarOrString ΒΆ added in v0.6.0
EnvVarOrString gets the environment variable for the provided key or the provided default string.
func EnvVarOrURL ΒΆ added in v0.6.0
EnvVarOrURL gets the environment variable for the provided or the provided default *url.URL.
func NewAppPropsContext ΒΆ added in v0.10.16
NewAppPropsContext adds props to ctx, returning the resulting context. If props have already been added to ctx, it's key-value pairs are added to existing ones. If any keys collide, those in props overwrite previous values.
func NewLogLevel ΒΆ added in v0.7.0
NewLogLevel translates val into a golang.org/x/exp/slog.Level
Types ΒΆ
type AccessState ΒΆ
type AccessState string
AccessState is a string representation of the broadest, general access an entity such as an Account or a User has to a trails application.
const ( AccessGranted AccessState = "granted" AccessInvited AccessState = "invited" AccessRevoked AccessState = "revoked" AccessVerifyEmail AccessState = "verify-email" )
func (AccessState) String ΒΆ
func (as AccessState) String() string
String stringifies the AccessState.
String implements fmt.Stringer.
type Account ΒΆ
type Account struct { Model AccessState AccessState `json:"accessState"` AccountOwnerID uint `json:"accountOwnerId"` // Associations AccountOwner *User `json:"accountOwner,omitempty"` Users []User `json:"users,omitempty"` }
An Account is a way many Users access a trails application and can be related to one another.
An Account has many Users. An Account has one User designated as the owner of the Account.
type AppProps ΒΆ added in v0.10.16
An AppProps passes data from the server to the client as a set of props needed for general application state. The data is passed around in a context.Context and rendered as JSON. The data is expected to be marshaled into Vue/JS props.
NB: Data not representable by JSON will create errors; review encoding/json.Marshaler.
func AppPropsFromContext ΒΆ added in v0.10.16
AppPropsFromContext retrieves an AppProps in ctx. If not already set, it initializes a new AppProps.
type DeletedTime ΒΆ
DeletedTime is a nullable timestamp marking a record as soft deleted.
func (DeletedTime) DeleteClauses ΒΆ
func (DeletedTime) DeleteClauses(f *schema.Field) []clause.Interface
Implements GORM-specific interfaces for modifying queries when DeletedTime is valid cf.: - https://github.com/go-gorm/gorm/blob/8dde09e0becd383bc24c7bd7d17e5600644667a8/soft_delete.go
func (DeletedTime) IsDeleted ΒΆ
func (dt DeletedTime) IsDeleted() bool
IsDeleted asserts whether the record is soft deleted.
func (DeletedTime) QueryClauses ΒΆ
func (DeletedTime) QueryClauses(f *schema.Field) []clause.Interface
func (DeletedTime) UpdateClauses ΒΆ
func (DeletedTime) UpdateClauses(f *schema.Field) []clause.Interface
type Environment ΒΆ added in v0.6.0
type Environment string
An Environment is a different context in which a trails app operates.
const ( Demo Environment = "DEMO" Development Environment = "DEVELOPMENT" Production Environment = "PRODUCTION" Review Environment = "REVIEW" Staging Environment = "STAGING" Testing Environment = "TESTING" )
func EnvVarOrEnv ΒΆ added in v0.6.0
func EnvVarOrEnv(key string, def Environment) Environment
EnvVarOrEnv gets the environment variable for the provided key, casts it into an Environment, or returns the provided default Environment if key is not a valid Environment.
func (Environment) CanUseServiceStub ΒΆ added in v0.6.0
func (e Environment) CanUseServiceStub() bool
CanUseServiceStub asserts whether the Environment allows for setting up with stubbed out services, for those services that support stubbing.
func (Environment) IsDemo ΒΆ added in v0.6.0
func (e Environment) IsDemo() bool
func (Environment) IsDevelopment ΒΆ added in v0.6.0
func (e Environment) IsDevelopment() bool
func (Environment) IsProduction ΒΆ added in v0.6.0
func (e Environment) IsProduction() bool
func (Environment) IsReview ΒΆ added in v0.6.0
func (e Environment) IsReview() bool
func (Environment) IsStaging ΒΆ added in v0.6.0
func (e Environment) IsStaging() bool
func (Environment) IsTesting ΒΆ added in v0.6.0
func (e Environment) IsTesting() bool
func (Environment) String ΒΆ added in v0.6.0
func (e Environment) String() string
func (Environment) ToolboxEnabled ΒΆ added in v0.6.0
func (e Environment) ToolboxEnabled() bool
ToolboxEnabled asserts whether the Environment enables the client-side toolbox.
func (Environment) Valid ΒΆ added in v0.6.0
func (e Environment) Valid() error
type Key ΒΆ added in v0.6.1
type Key string
const ( // CurrentUserKey stashes the currentUser for a session. CurrentUserKey Key = "CurrentUserKey" // IpAddrKey stashes the IP address of an HTTP request being handled by trails. IpAddrKey Key = "IpAddrKey" // RequestIDKey stashes a unique UUID for each HTTP request. RequestIDKey Key = "RequestIDKey" // SessionKey stashes the session associated with an HTTP request. SessionKey Key = "SessionKey" // SessionIDKey stashes a unique UUID for each session. SessionIDKey Key = "SessionIDKey" )
type Model ΒΆ
type Model struct { ID uint `json:"id"` CreatedAt time.Time `json:"createdAt"` UpdatedAt time.Time `json:"updatedAt"` DeletedAt DeletedTime `json:"deletedAt"` }
A Model is the essential data points for primary ID-based models in a trails application, indicating when a record was created, last updated and soft deleted.
type Tool ΒΆ added in v0.6.1
type Tool struct { Actions []ToolAction `json:"actions"` Title string `json:"title"` }
A Tool is a set of actions grouped under a category. A Tool may pertain to a part of the domain, grouping actions touching similar models.
type ToolAction ΒΆ added in v0.6.1
A ToolAction is a specific link the end user can follow to execute the named action.
type Toolbox ΒΆ added in v0.6.1
type Toolbox []Tool
A Toolbox is a set of Tools exposed to the end user in certain environments, notably, not in Production. Generally, these are administrative tools that simplify demonstrating features which would otherwise require actions taken in many steps.
type User ΒΆ
type User struct { Model AccessState AccessState `json:"accessState"` AccountID uint `json:"accountId"` Email string `json:"email"` ExternalID uuid.UUID `json:"externalId"` Password []byte `json:"-"` // Associations Account *Account `json:"account,omitempty"` }
A User is the core entity that interacts with a trails application.
An agent's HTTP requests are authenticated first by a specific request with email & password data matching credentials stored on a DB record for a User. Upon a match, a session is created and stored. Further requests are authenticated by referencing that session.
A User has one Account.
Source Files ΒΆ
Directories ΒΆ
Path | Synopsis |
---|---|
http
|
|
middleware
The middleware package defines what a middleware is in trails and a set of basic middlewares.
|
The middleware package defines what a middleware is in trails and a set of basic middlewares. |
resp
Package resp provides a high-level API for responding to HTTP requests.
|
Package resp provides a high-level API for responding to HTTP requests. |
router
Package router defines what an HTTP server is and a default implementation of it.
|
Package router defines what an HTTP server is and a default implementation of it. |
template/templatetest
Package templatetest exposes a mock fs.FS that implements basic file operations.
|
Package templatetest exposes a mock fs.FS that implements basic file operations. |
Package logger provides logging functionality to a trails app by defining the required behavior in Logger and providing an implementation of it with TrailsLogger.
|
Package logger provides logging functionality to a trails app by defining the required behavior in Logger and providing an implementation of it with TrailsLogger. |
Package postgres manages our database connection.
|
Package postgres manages our database connection. |
Package ranger initializes and manages a trails app with sane defaults.
|
Package ranger initializes and manages a trails app with sane defaults. |