nacl

package module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2021 License: MIT Imports: 6 Imported by: 0

README

nacl

Client helper for NATS/STAN

examples

connect to NATS

package main

import (
    "fmt"
    "github.com/jar3b/grawt"
    "github.com/jar3b/nacl"
    "github.com/kelseyhightower/envconfig"
)

func main() {
    // get params
    conf := config.NewConfig()

	// init waiter (github.com/jar3b/grawt)
	var waiter = grawt.NewWaiter()

	// init nats
	var subscriptions []*nacl.NatsSubscription
	if err := nacl.SetupNats(conf.Nats.Host, conf.Nats.Port, conf.Nats.User, conf.Nats.Pass,
		// handler called before app closed
        // we need to terminate sub's properly and sometimes doing another actions (finalizers)
        waiter.AddCloseHandler(func() {
			nacl.FinalizeNats(&subscriptions)
		}, false),
	); err != nil {
		waiter.Halt(fmt.Errorf("cannot connect to nats: %v", err))
	}
	defer nacl.NatsClient.Close()
	
    // here we add some subscriptions and wait (using blocking call)
    // ...
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	NatsClient *nats.Conn
	StanClient stan.Conn
)

Functions

func FinalizeNats added in v0.0.2

func FinalizeNats(subscriptions *[]*nats.Subscription) error

func FinalizeStan

func FinalizeStan(subscriptions *[]stan.Subscription) error

func SetupNats

func SetupNats(host string, port int, user string, pass string, closeHandler *grawt.CloseHandler) error

func SetupNatsWithCreds added in v0.1.2

func SetupNatsWithCreds(host string, port int, credsFile string, closeHandler *grawt.CloseHandler) error

func SetupStan

func SetupStan(clusterName string, clientId string, host string, port int, user string, pass string, closeHandler *grawt.CloseHandler) (err error)

Types

This section is empty.

Jump to

Keyboard shortcuts

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