-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds a connect-only natscontext (#5)
This adds a version of natscontext that supports only the parts needed to connect to nats and none of the management features the CLI needs, this is in order to keep the usage API and dependencies low Signed-off-by: R.I.Pienaar <[email protected]>
- Loading branch information
Showing
15 changed files
with
724 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
name: natscontext | ||
on: | ||
push: | ||
paths: | ||
- 'natscontext/**' | ||
|
||
pull_request: | ||
paths: | ||
- 'natscontext/**' | ||
|
||
|
||
jobs: | ||
lint: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup Go | ||
uses: actions/setup-go@v5 | ||
with: | ||
go-version: 'stable' | ||
|
||
- name: Install deps | ||
working-directory: natscontext | ||
shell: bash --noprofile --norc -x -eo pipefail {0} | ||
run: | | ||
go get -t ./... | ||
go install honnef.co/go/tools/cmd/staticcheck@latest | ||
go install github.com/client9/misspell/cmd/misspell@latest | ||
- name: Run linters | ||
working-directory: natscontext | ||
shell: bash --noprofile --norc -x -eo pipefail {0} | ||
run: | | ||
$(exit $(go fmt ./... | wc -l)) | ||
go vet ./... | ||
go vet ./test/... | ||
staticcheck ./... | ||
staticcheck ./test/... | ||
find . -type f -name "*.go" | xargs misspell -error -locale US | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup Go | ||
uses: actions/setup-go@v5 | ||
with: | ||
go-version: 'stable' | ||
|
||
- name: Run tests | ||
working-directory: natscontext | ||
shell: bash --noprofile --norc -x -eo pipefail {0} | ||
run: | | ||
go test -v -count=1 ./... | ||
go test -v -count=1 ./test/... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# NATS Context Connection Helper | ||
|
||
This is a package that helps Go developers connect to NATS using a NATS Context as featured in the `nats` Command Line | ||
Tool. | ||
|
||
## Installation | ||
|
||
```bash | ||
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: | ||
|
||
```bash | ||
nats context add staging --creds /home/user/staging.creds --js-domain STAGING | ||
``` | ||
|
||
We can now use the context called `staging` from Go: | ||
|
||
```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. |
Oops, something went wrong.