natscontext

package
v0.0.19 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2020 License: Apache-2.0 Imports: 9 Imported by: 0

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

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 (*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) 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) 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) NKey

func (c *Context) NKey() string

NKey retrieves the configured nkey path, empty if not set

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

func (c *Context) User() string

User is the configured username, empty if not set

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 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 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 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 WithUser

func WithUser(u string) Option

WithUser sets the username

Jump to

Keyboard shortcuts

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