natscontext

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2024 License: Apache-2.0 Imports: 13 Imported by: 32

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func Connect added in v0.0.25

func Connect(name string, opts ...nats.Option) (*nats.Conn, error)

Connect connects to the NATS server configured by the named context, empty name connects to selected context

func ContextPath

func ContextPath(name string) (string, error)

ContextPath is the path on disk to store the context

func DeleteContext

func DeleteContext(name string) error

DeleteContext deletes a context with a given name, the active context can not be deleted unless it's the only context

func IsKnown

func IsKnown(name string) bool

IsKnown determines if a context is known

func KnownContexts

func KnownContexts() []string

KnownContexts is a list of known context

func SelectContext

func SelectContext(name string) error

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

func New(name string, load bool, opts ...Option) (*Context, error)

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

func NewFromFile(filename string, opts ...Option) (*Context, error)

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) CA

func (c *Context) CA() string

CA retrieves the CA file path, empty if not set

func (*Context) Certificate

func (c *Context) Certificate() string

Certificate retrieves the path to the public certificate, empty if not set

func (*Context) ColorScheme added in v0.1.0

func (c *Context) ColorScheme() string

ColorScheme is a color scheme hint for CLI tools, valid values depend on the tool

func (*Context) Connect added in v0.0.25

func (c *Context) Connect(opts ...nats.Option) (*nats.Conn, error)

Connect connects to the configured NATS server

func (*Context) Creds

func (c *Context) Creds() string

Creds retrieves the configured credentials file path, empty if not set

func (*Context) Description

func (c *Context) Description() string

Description retrieves the description, empty if not set

func (*Context) InboxPrefix added in v0.0.29

func (c *Context) InboxPrefix() string

InboxPrefix is the configured inbox prefix for request-reply inboxes

func (*Context) JSAPIPrefix

func (c *Context) JSAPIPrefix() string

JSAPIPrefix is the subject prefix to use when accessing JetStream API

func (*Context) JSDomain added in v0.0.24

func (c *Context) JSDomain() string

JSDomain is the configured JetStream domain

func (*Context) JSEventPrefix

func (c *Context) JSEventPrefix() string

JSEventPrefix is the subject prefix to use when accessing JetStream events

func (*Context) Key

func (c *Context) Key() string

Key retrieves the private key path, empty if not set

func (*Context) MarshalJSON

func (c *Context) MarshalJSON() ([]byte, error)

func (*Context) NATSOptions

func (c *Context) NATSOptions(opts ...nats.Option) ([]nats.Option, error)

NATSOptions creates NATS client configuration based on the contents of the context

func (*Context) NKey

func (c *Context) NKey() string

NKey retrieves the configured nkey path, empty if not set

func (*Context) NscURL

func (c *Context) NscURL() string

NscURL is the url used to resolve credentials in nsc

func (*Context) Password

func (c *Context) Password() string

Password retrieves the configured password, empty if not set

func (*Context) Path

func (c *Context) Path() string

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) Save

func (c *Context) Save(name string) error

Save saves the current context to name

func (*Context) ServerURL

func (c *Context) ServerURL() string

ServerURL is the configured server urls, 'nats://localhost:4222' if not set

func (*Context) SocksProxy added in v0.1.0

func (c *Context) SocksProxy() string

SocksProxy retrieves the configured SOCKS5 Proxy, empty if not set

func (*Context) TLSHandshakeFirst added in v0.1.1

func (c *Context) TLSHandshakeFirst() bool

TLSHandshakeFirst configures the connection to do a TLS Handshake before expecting server INFO

func (*Context) Token added in v0.0.24

func (c *Context) Token() string

Token retrieves the configured token, empty if not set

func (*Context) User

func (c *Context) User() string

User is the configured username, empty if not set

func (*Context) UserJWT added in v0.0.34

func (c *Context) UserJWT() string

UserJWT retrieves the configured user jwt, empty if not set

func (*Context) Validate added in v0.1.0

func (c *Context) Validate() error

type Option

type Option func(c *settings)

func WithCA

func WithCA(ca string) Option

WithCA sets the CA certificate path to use

func WithCertificate

func WithCertificate(c string) Option

WithCertificate sets the path to the public certificate

func WithColorScheme added in v0.1.0

func WithColorScheme(scheme string) Option

WithColorScheme allows a color scheme to be recorded, valid values depend on the tool

func WithCreds

func WithCreds(c string) Option

WithCreds sets the credentials file

func WithDescription

func WithDescription(d string) Option

WithDescription sets a freiendly description for this context

func WithInboxPrefix added in v0.0.29

func WithInboxPrefix(p string) Option

WithInboxPrefix sets a custom prefix for request-reply inboxes

func WithJSAPIPrefix

func WithJSAPIPrefix(p string) Option

WithJSAPIPrefix sets the prefix to use for JetStream API

func WithJSDomain added in v0.0.24

func WithJSDomain(domain string) Option

func WithJSEventPrefix

func WithJSEventPrefix(p string) Option

WithJSEventPrefix sets the prefix to use for JetStream Events

func WithKey

func WithKey(k string) Option

WithKey sets the private key path to use

func WithNKey

func WithNKey(n string) Option

WithNKey sets the nkey path

func WithNscUrl

func WithNscUrl(u string) Option

WithNscUrl queries nsc for a credential based on a url like nsc://<operator>/<account>/<user>

func WithPassword

func WithPassword(p string) Option

WithPassword sets the password

func WithServerURL

func WithServerURL(url string) Option

WithServerURL supplies the url(s) to connect to nats with

func WithSocksProxy added in v0.1.0

func WithSocksProxy(p string) Option

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

func WithToken added in v0.0.24

func WithToken(t string) Option

WithToken sets the token to use for authentication

func WithUser

func WithUser(u string) Option

WithUser sets the username

func WithUserJWT added in v0.0.34

func WithUserJWT(p string) Option

WithUserJWT sets the user jwt

type SocksDialer added in v0.1.0

type SocksDialer struct {
	// contains filtered or unexported fields
}

SocksDialer should satisfy the NATS CustomDialer interface

func (SocksDialer) Dial added in v0.1.0

func (sd SocksDialer) Dial(network, address string) (net.Conn, error)

Jump to

Keyboard shortcuts

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