Documentation ¶
Overview ¶
Package config loads a tir configuration, either from a JSON file (e.g. $HOME/.tir.config), from command-line arguments if the config variables are bound with viper.BindPFlag, or from environment variables (though the latter are not explicitly supported).
Loading a Config generates a tir.Interface for interacting with the configured store and a text.Editor for getting user input.
Defaults ¶
In the absence of explicit configuration, Load yields a Config backed by a store.File store pointing at $HOME/.tir.json and an edit.Tea editor.
Index ¶
Constants ¶
const ( // KeyStoreGroup is the top-level key for store configuration. KeyStoreGroup = "store" // KeyStoreType must match a StoreType. KeyStoreType = KeyStoreGroup + ".type" // KeyFileStoreLocation must be defined for file stores. KeyFileStoreLocation = KeyStoreGroup + ".path" // KeyHTTPStoreBaseURL must be defined for HTTP stores. KeyHTTPStoreBaseURL = KeyStoreGroup + ".base_url" // KeyHTTPStoreAPISecret defines an API secret to authorize requests to // the tir server at base_url. This is an optional config variable, but a // server that requires it will reject requests. KeyHTTPStoreAPISecret = KeyStoreGroup + ".api_secret" // KeyEditor is the top-level key for CLI editor configuration. KeyEditor = "editor" )
Values providable via a JSON config file. For example, this .tir.config file configures tir to use a file store rooted at /Users/me/.tir.json and the Tea editor:
{ "store": { "type": "file", "path": "/Users/me/.tir.json" }, "editor": "tea" }
For comparison, this .tir.config file configures tir to talk to a server at tir.example.com:
{ "store": { "type": "http", "base_url": "https://tir.example.com", "api_secret": "YOUR_SECRET" } }
For info on where tir looks for a config, see Load. For info about how to provide configuration, see viper.
const ( // StoreTypeFile selects the store.file store (default). StoreTypeFile storeType = "file" // StoreTypeMemory selects the store.memory store. StoreTypeMemory storeType = "memory" // StoreTypeMemory selects the store.http store. StoreTypeHTTP storeType = "http" )
Possible values for the store.type config variable. Providing any other store type value will cause Load to fail.
const ( // EditorTypeVim selects the edit.Vim editor. EditorTypeVim editorType = "vim" // EditorTypeTea selects the edit.Tea editor (default). EditorTypeTea editorType = "tea" )
Possible values for the editor config variable. Providing any other editor value will cause Load to fail.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { App tir.Interface Editor text.Editor // contains filtered or unexported fields }
Config for a Service and Editor. Use Load to construct a Config that respects the viper-provided user configuration environment.
func Load ¶
Load loads a tir configuration from user-provided configuration. Users can provide configuration via a JSON config file, via environment variables, or through command-line arguments with the appropriate viper bindings.
The default tir.Interface is backed by a file at $HOME/.tir.json. The default text.Editor is edit.Tea.
The caller is responsible for calling tir.Interface.Close appropriately.
func (*Config) GetAPISecret ¶
GetAPISecret provided through viper or the env variable TIR_API_SECRET if it's present.
The standard post-prefixing key for this value is unwieldy (TIR_STORE.API_SECRET), hence the TIR_API_SECRET alias.