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) ColorScheme() string
- func (c *Context) Connect(opts ...nats.Option) (*nats.Conn, error)
- func (c *Context) Creds() string
- func (c *Context) Description() string
- func (c *Context) InboxPrefix() 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) SOCKSDialer() SocksDialer
- func (c *Context) Save(name string) error
- func (c *Context) ServerURL() string
- func (c *Context) SocksProxy() string
- func (c *Context) TLSHandshakeFirst() bool
- func (c *Context) Token() string
- func (c *Context) User() string
- func (c *Context) UserJWT() string
- func (c *Context) Validate() error
- type Option
- func WithCA(ca string) Option
- func WithCertificate(c string) Option
- func WithColorScheme(scheme string) Option
- func WithCreds(c string) Option
- func WithDescription(d string) Option
- func WithInboxPrefix(p 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 WithSocksProxy(p string) Option
- func WithTLSHandshakeFirst() Option
- func WithToken(t string) Option
- func WithUser(u string) Option
- func WithUserJWT(p string) Option
- type SocksDialer
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 unless it's the only context
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 NewFromFile ¶ added in v0.0.31
NewFromFile loads a new configuration context from the given filename.
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) ColorScheme ¶ added in v0.1.0
ColorScheme is a color scheme hint for CLI tools, valid values depend on the tool
func (*Context) Description ¶
Description retrieves the description, empty if not set
func (*Context) InboxPrefix ¶ added in v0.0.29
InboxPrefix is the configured inbox prefix for request-reply inboxes
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) SOCKSDialer ¶ added in v0.1.0
func (c *Context) SOCKSDialer() SocksDialer
func (*Context) ServerURL ¶
ServerURL is the configured server urls, 'nats://localhost:4222' if not set
func (*Context) SocksProxy ¶ added in v0.1.0
SocksProxy retrieves the configured SOCKS5 Proxy, empty if not set
func (*Context) TLSHandshakeFirst ¶ added in v0.1.1
TLSHandshakeFirst configures the connection to do a TLS Handshake before expecting server INFO
type Option ¶
type Option func(c *settings)
func WithCertificate ¶
WithCertificate sets the path to the public certificate
func WithColorScheme ¶ added in v0.1.0
WithColorScheme allows a color scheme to be recorded, valid values depend on the tool
func WithDescription ¶
WithDescription sets a freiendly description for this context
func WithInboxPrefix ¶ added in v0.0.29
WithInboxPrefix sets a custom prefix for request-reply inboxes
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
func WithSocksProxy ¶ added in v0.1.0
WithSocksProxy sets the SOCKS5 Proxy. To explicitly remove an already configured proxy, use the string "none".
func WithTLSHandshakeFirst ¶ added in v0.1.1
func WithTLSHandshakeFirst() Option
WithTLSHandshakeFirst configures the client to send TLS handshakes before waiting for server INFO
type SocksDialer ¶ added in v0.1.0
type SocksDialer struct {
// contains filtered or unexported fields
}
SocksDialer should satisfy the NATS CustomDialer interface