Documentation
¶
Overview ¶
Package natscontext provides a way for sets of configuration options to be stored in named files and later retrieved either by name or if no name is supplied by access a chosen default context.
Files are stored in ~/.config/nats or in the directory set by XDG_CONFIG_HOME environment
.config/nats .config/nats/context .config/nats/context/ngs.js.json .config/nats/context/ngs.stats.json .config/nats/context.txt
Here the context.txt holds simply the string matching a context name like 'ngs.js'
Index ¶
- func Connect(name string, opts ...nats.Option) (*nats.Conn, error)
- func ContextPath(name string) (string, error)
- func DeleteContext(name string) error
- func IsKnown(name string) bool
- func KnownContexts() []string
- func SelectContext(name string) error
- func SelectedContext() string
- type Context
- func (c *Context) CA() string
- func (c *Context) Certificate() string
- func (c *Context) Connect(opts ...nats.Option) (*nats.Conn, error)
- func (c *Context) Creds() string
- func (c *Context) Description() string
- func (c *Context) JSAPIPrefix() string
- func (c *Context) JSDomain() string
- func (c *Context) JSEventPrefix() string
- func (c *Context) Key() string
- func (c *Context) MarshalJSON() ([]byte, error)
- func (c *Context) NATSOptions(opts ...nats.Option) ([]nats.Option, error)
- func (c *Context) NKey() string
- func (c *Context) NscURL() string
- func (c *Context) Password() string
- func (c *Context) Path() string
- func (c *Context) Save(name string) error
- func (c *Context) ServerURL() string
- func (c *Context) Token() string
- func (c *Context) User() string
- type Option
- func WithCA(ca string) Option
- func WithCertificate(c string) Option
- func WithCreds(c string) Option
- func WithDescription(d string) Option
- func WithJSAPIPrefix(p string) Option
- func WithJSDomain(domain string) Option
- func WithJSEventPrefix(p string) Option
- func WithKey(k string) Option
- func WithNKey(n string) Option
- func WithNscUrl(u string) Option
- func WithPassword(p string) Option
- func WithServerURL(url string) Option
- func WithToken(t string) Option
- func WithUser(u string) Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Connect ¶ added in v0.0.25
Connect connects to the NATS server configured by the named context, empty name connects to selected context
func ContextPath ¶
ContextPath is the path on disk to store the context
func DeleteContext ¶
DeleteContext deletes a context with a given name, the active context can not be deleted
func SelectContext ¶
SelectContext sets the given context to be the default, error if it does not exist
func SelectedContext ¶
func SelectedContext() string
SelectedContext returns the name of the current selected context, empty when non is selected
Types ¶
type Context ¶
type Context struct { Name string `json:"-"` // contains filtered or unexported fields }
func New ¶
New loads a new configuration context. If name is empty the current active one will be loaded. If load is false no loading of existing data is done this is mainly useful to create new empty contexts.
When opts is supplied those settings will override what was loaded or supply values for an empty context
func (*Context) Certificate ¶
Certificate retrieves the path to the public certificate, empty if not set
func (*Context) Description ¶
Description retrieves the description, empty if not set
func (*Context) JSAPIPrefix ¶
JSAPIPrefix is the subject prefix to use when accessing JetStream API
func (*Context) JSEventPrefix ¶
JSEventPrefix is the subject prefix to use when accessing JetStream events
func (*Context) MarshalJSON ¶
func (*Context) NATSOptions ¶
NATSOptions creates NATS client configuration based on the contents of the context
func (*Context) Path ¶
Path returns the path on disk for a loaded context, empty when not saved or loaded
func (*Context) ServerURL ¶
ServerURL is the configured server urls, 'nats://localhost:4222' if not set
type Option ¶
type Option func(c *settings)
func WithCertificate ¶
WithCertificate sets the path to the public certificate
func WithDescription ¶
WithDescription sets a freiendly description for this context
func WithJSAPIPrefix ¶
WithJSAPIPrefix sets the prefix to use for JetStream API
func WithJSDomain ¶ added in v0.0.24
func WithJSEventPrefix ¶
WithJSEventPrefix sets the prefix to use for JetStream Events
func WithNscUrl ¶
WithNscUrl queries nsc for a credential based on a url like nsc://<operator>/<account>/<user>
func WithServerURL ¶
WithServerURL supplies the url(s) to connect to nats with