Categorygithub.com/wuespace/telestion/backend-go
modulepackage
1.0.0-goalpha.4
Repository: https://github.com/wuespace/telestion.git
Documentation: pkg.go.dev

# README

Telestion Service Framework for Go

DOI: 10.5281/zenodo.10407142 GitHub License: MIT

This library provides a framework for building Telestion services in Go.

Installation

Install the library via go get:

go get -u github.com/wuespace/telestion/backend-go@latest

Basic Usage

package main

import (
	"github.com/wuespace/telestion/backend-go"
	"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. 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.

# Packages

No description provided by the author

# Functions

StartService starts a new Telestion service and returns the available APIs.
WaitForInterrupt blocks the execution of the current goroutine.
WithCustomNc gives [StartService] externally managed NATS connections.
WithoutNats disables the NATS initialization step in [StartService].
WithOverwriteArgs passes additional configuration parameters to [StartService].

# Structs

Config configures the Telestion service.
Options describes the different options [Option] can change to modify the startup behaviour of [StartService].
Service is a Telestion service that provides the available APIs.

# Type aliases

Option takes the startup options from [StartService] and modifies the startup behaviour.