Categorygithub.com/skysoft-atm/gorillaz
modulepackage
0.8.43
Repository: https://github.com/skysoft-atm/gorillaz.git
Documentation: pkg.go.dev

# README

Build Status

gorillaz: a Go common library

Gorillaz offers:

Opinionated config

Setup your project config in configs/application.properties You can override values by passing flags on the command line.

A service name and an environment must be provided in the configuration

service.name=testProducer
env=uat

A web server

A common we server is started for metrics and healthchecks. You can configure its port with this property:

http.port=12347

Health check endpoints

2 health check endpoints that can be used for example in Kubernetes are provided:

/live /ready

You can control them in the application with:

gaz.SetLive(true)
gaz.SetReady(true)

They can be enabled or disabled with this property:

healtheck.enabled=false

Prometheus integration

Running gorillaz starts a prometheus endpoint to collect metrics: /metrics

You can disable this endpoint with this property:

prometheus.enabled=false

Logging

Gorillaz offers 2 loggers:

gorillaz.Log is a zap.Logger that offers good performance but requires a bit more work when logging variables:

gorillaz.Log.Error("Error while doing something", zap.Error(err))

gorillaz.Sugar is a zap.SugaredLogger that is slower but more convenient

gorillaz.Sugar.Error("Error while doing something %v", err)

The log level is configured through this property:

log.level=info

Easy streaming over gRPC

Producer:

g := gorillaz.New()

p, err := g.NewStreamProvider("myNiceStream", "my stream data type")
if err != nil {
    panic(err)
}

g.Run()

// Submit a value every second
for {
    event := &stream.Event{
        Value: []byte("something wonderful"),
    }
    p.Submit(event)
    time.Sleep(1 * time.Second)
}
    

Consumer:

g := gorillaz.New()
consumer, err := g.ConsumeStream([]string{"localhost:9090"}, "myStreamName")
if err != nil {
    panic(err)
}

for evt := range consumer.EvtChan() {
    fmt.Println(evt)
}

Consumer with service discovery:

g := gorillaz.New()
consumer, err := g.DiscoverAndConsumeServiceStream("myServiceName", "myStreamName")
if err != nil {
    panic(err)
}

for evt := range consumer.EvtChan() {
    fmt.Println(evt)
}

You will find more complete examples in the cmd folder

The gRPC port is configured with this property, it assigns a random port by default:

grpc.port=9666

Tracing

Tracing is done through Zipkin, it can be enable with this property:

tracing.enabled=true

If service discovery is enabled, gorillaz will try to resolve the 'zipkin' service to find its endpoint. Otherwise you can configure it with this property:

tracing.collector.url=http://127.0.0.1:9411/api/v1/spans // if you do not configure zipkin with the service discovery

# Packages

No description provided by the author
Provides pubsub of messages over channels.
No description provided by the author
No description provided by the author

# Functions

No description provided by the author
No description provided by the author
No description provided by the author
with this option the configuration keys define in the config file will be declared as flags, and the flag default value will be the value from the config file.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
New initializes the different modules (Logger, Metrics, ready and live Probes and Properties) It takes root at the current folder for properties file and a map of properties.
No description provided by the author
No description provided by the author
returns the service name and stream name.
Publishes the given broadcaster on a websocket, the buffer size configures the buffer on the channel reading from the broadcaster.
Publishes the given broadcaster on a websocket, the buffer size configures the buffer on the channel reading from the broadcaster.
Publishes the given state broadcaster on a websocket, the buffer size configures the buffer on the channel reading from the state broadcaster.
serves a file as an http response.
Upgrades the http request to a websocket connection and returns - a channel to publish websocket messages - a channel signaling that an error occurred and the publication has stopped - an error if the upgrade was not successful.
WithAutoAck automatic acknowledge message received if MsgHandle returns no error.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
WithQueue configures Nats Queue consumer.
No description provided by the author
Add options for the stream endpoint creation, this can be used when stream endpoints are created under the hood by the methods below.
No description provided by the author
No description provided by the author
No description provided by the author

# Constants

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Prometheus metrics.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Variables

set at build time, go build -ldflags "-X github.com/skysoft-atm/gorillaz.ApplicationVersion=v0.3.2 -X github.com/skysoft-atm/gorillaz.ApplicationName=srv-cheesy-cheese -X github.com/skysoft-atm/gorillaz.ApplicationDescription=bla_pepito".
set at build time, go build -ldflags "-X github.com/skysoft-atm/gorillaz.ApplicationVersion=v0.3.2 -X github.com/skysoft-atm/gorillaz.ApplicationName=srv-cheesy-cheese -X github.com/skysoft-atm/gorillaz.ApplicationDescription=bla_pepito".
set at build time, go build -ldflags "-X github.com/skysoft-atm/gorillaz.ApplicationVersion=v0.3.2 -X github.com/skysoft-atm/gorillaz.ApplicationName=srv-cheesy-cheese -X github.com/skysoft-atm/gorillaz.ApplicationDescription=bla_pepito".
No description provided by the author
Log is the main logger.
Sugar is.
No description provided by the author

# Structs

No description provided by the author
No description provided by the author
No description provided by the author
ProviderConfig is the configuration that will be applied for the stream StreamProvider.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
ProviderConfig is the configuration that will be applied for the stream StreamProvider.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Websocket message.

# Interfaces

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Type aliases

No description provided by the author
No description provided by the author
No description provided by the author
MsgHandler handles received events from Nats If NatsConsumerOpts.AutoAck is set, if MsgHandler returns no error, the message will be acknowledged.
No description provided by the author
No description provided by the author
ProviderConfigOpt is a ProviderConfig option function to modify the ProviderConfig used by the stream StreamProvider.
No description provided by the author
No description provided by the author
No description provided by the author