-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce Config type to configure startService with variadic arguments. Add godoc to all public types and functions. Rename multiple config parsers for better readability. Add first godoc example. Add more samples. Add LICENSE. Add README.md Fix various nil pointer reference errors.
- Loading branch information
Showing
15 changed files
with
437 additions
and
81 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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2024 WüSpace e. V. | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,71 @@ | ||
# Telestion Service Framework for Go | ||
|
||
[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.10407142.svg)](https://doi.org/10.5281/zenodo.10407142) | ||
![GitHub License](https://img.shields.io/github/license/wuespace/telestion) | ||
[![Go Reference](https://pkg.go.dev/badge/github.com/wuespace/telestion/backend.svg)](https://pkg.go.dev/github.com/wuespace/telestion/backend) | ||
|
||
This library provides a framework for building Telestion services in Go. | ||
|
||
## Installation | ||
|
||
Install the library via `go get`: | ||
|
||
```shell | ||
go get -u github.com/wuespace/telestion/backend@latest | ||
``` | ||
|
||
## Basic Usage | ||
|
||
```go | ||
package main | ||
|
||
import ( | ||
"github.com/wuespace/telestion/backend" | ||
"log" | ||
) | ||
|
||
type Person struct { | ||
Name string `json:"name"` | ||
Address string `json:"address"` | ||
} | ||
|
||
func main() { | ||
// start a new Telestion service | ||
service, err := telestion.StartService() | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
log.Println("Service started") | ||
|
||
// publish a message on the message bus | ||
service.Nc.Publish("my-topic", []byte("Hello from Go!")) | ||
|
||
// subscribe to receive messages from the message bus | ||
// automatically unmarshal JSON message to go struct | ||
_, err = service.NcJson.Subscribe("registered-person-topic", func(person *Person) { | ||
log.Println("Received new personal information:", person) | ||
}) | ||
if err != nil { | ||
log.Println(err) | ||
} | ||
|
||
// wait for interrupts to prevent immediate shutdown of service | ||
telestion.WaitForInterrupt() | ||
|
||
// drain remaining messages and close connection | ||
if err1, err2 := service.Drain(); err1 != nil || err2 != nil { | ||
log.Fatal(err1, err2) | ||
} | ||
} | ||
``` | ||
|
||
## Behavior Specification | ||
|
||
The behavior of this library is specified in | ||
the [Behavior Specification](https://docs.telestion.wuespace.de/Backend%20Development/service-behavior/). | ||
This specification is also used to test the library. | ||
The source code of the tests can be found in the repository under `/backend-features`. | ||
|
||
## License | ||
|
||
This project is licensed under the terms of the [MIT license](LICENSE). |
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 @@ | ||
package telestion_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package telestion_test | ||
|
||
import ( | ||
"github.com/nats-io/nats.go" | ||
"github.com/wuespace/telestion/backend" | ||
) | ||
|
||
// The WaitForInterrupt function waits for an external interrupt | ||
// to prevent immediate shutdown of the service. | ||
func ExampleWaitForInterrupt() { | ||
// start a new Telestion service | ||
service, _ := telestion.StartService() | ||
|
||
// subscribe to a subject on the message bus | ||
_, _ = service.Nc.Subscribe("subject", func(msg *nats.Msg) { | ||
//... | ||
}) | ||
|
||
// wait for external interrupt to prevent immediate shutdown of service | ||
telestion.WaitForInterrupt() | ||
|
||
// drain NATS connections | ||
_, _ = service.Drain() | ||
} |
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
Oops, something went wrong.