natscontext

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2024 License: Apache-2.0 Imports: 11 Imported by: 1

README

NATS Context Connection Helper

License Go Reference Build Status Go Report Card

This is a package that helps Go developers connect to NATS using a NATS Context as featured in the nats Command Line Tool.

Installation

go get github.com/synadia-io/orbit.go/natscontext

Usage

Using the nats command line create a Context that can connect to your server, here we use a credential in a file:

nats context add staging --creds /home/user/staging.creds --js-domain STAGING

We can now use the context called staging from Go:

nc, settings, err := natscontext.Connect("staging", nats.Name("my application"))
if err != nil {
	// handle error
}

// Get a JetStream handle using the domain in the context
js, err := jetstream.NewWithDomain(nc, settings.JSDomain)
if err != nil {
	// handle error
}

If the full path to a context JSON file is given instead of the friendly name then that file will be used.

All context settings are supported except Windows Certificate Store related settings.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Settings

type Settings struct {
	Name        string `json:"name,omitempty"`
	Description string `json:"description"`
	URL         string `json:"url"`

	SocksProxy string `json:"socks_proxy"`
	Token      string `json:"token"`
	User       string `json:"user"`
	Password   string `json:"password"`
	Creds      string `json:"creds"`

	NKey                string   `json:"nkey"`
	Cert                string   `json:"cert"`
	Key                 string   `json:"key"`
	CA                  string   `json:"ca"`
	NSCLookup           string   `json:"nsc"`
	JSDomain            string   `json:"jetstream_domain"`
	JSAPIPrefix         string   `json:"jetstream_api_prefix"`
	JSEventPrefix       string   `json:"jetstream_event_prefix"`
	InboxPrefix         string   `json:"inbox_prefix"`
	UserJwt             string   `json:"user_jwt"`
	ColorScheme         string   `json:"color_scheme"`
	TLSFirst            bool     `json:"tls_first"`
	WinCertStoreType    string   `json:"windows_cert_store"`
	WinCertStoreMatchBy string   `json:"windows_cert_match_by"`
	WinCertStoreMatch   string   `json:"windows_cert_match"`
	WinCertStoreCaMatch []string `json:"windows_ca_certs_match"`
	// contains filtered or unexported fields
}

func Connect

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

Connect connects to the NATS server configured by the named context, empty name connects to selected context. If the name is a absolute name to a context configuration that will be used. The settings that are returned will include all the values from the Context so values like the JetStream Domain etc can be used later

type SocksDialer

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

SocksDialer should satisfy the NATS CustomDialer interface

func (SocksDialer) Dial

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