raccoon

package module
v0.0.0-...-83f64a2 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2023 License: Apache-2.0 Imports: 0 Imported by: 0

README

Raccoon Client Library for Go

Go Reference

Requirements

go 1.16 or above

Install

go get github.com/goto/raccoon/clients/go

Usage

Construct a new REST client, then use the various options on the client.

For example:

import "github.com/goto/raccoon/clients/go/rest"
client, err := rest.New(
	rest.WithUrl("http://localhost:8080/api/v1/events"),
	rest.WithHeader("x-user-id", "123"),
	rest.WithSerializer(serializer.PROTO), // default is JSON
)

see example: examples/rest

Construct a new GRPC client, then use the various options on the client.

For example:

import "github.com/goto/raccoon/clients/go/grpc"
client, err := grpc.New(
	grpc.WithAddr("http://localhost:8080"),
	grpc.WithHeader("x-user-id", "123"),
	grpc.WithDialOptions(
		g.WithTransportCredentials(credentials.NewServerTLSFromCert(&tls.Certificate{})),
	), // default is insecure
	// default serializer is proto.
)

see example: examples/grpc

Construct a new Websocket client, then use the various options on the client.

For example:

import "github.com/goto/raccoon/clients/go/ws"
client, err := ws.New(
	ws.WithUrl("ws://localhost:8080/api/v1/events"),
	ws.WithHeader("x-user-id", "123"),
	ws.WithHeader("x-user-type", "gojek"))
	// default serializer is proto.

Reading the message acknowledgements

resp := <-client.EventAcks()

see example: examples/websocket

Sending the request to raccoon
reqGuid, resp, err := client.Send([]*raccoon.Event{
        {
            Type: "page",
            Data: &testdata.PageEvent{
                EventGuid: uuid.NewString(),
                EventName: "clicked",
                SentTime:  timestamppb.Now(),
            },
        },
    })
Retry Configuration

Default settings, wait = 1 second, and maximum attempts = 3. The following options can override it.

rest.WithRetry(time.Second*2, 5)

grpc.WithRetry(time.Second*2, 5)
Custom Logging Configuration

The default logger logs the information to the standard output, and the default logger can be diabled by the following settings

rest.WithLogger(nil)
grpc.WithLogger(nil)

The client provide the logger interface that can be implemented by any logger.

type Logger interface {
	Infof(msg string, keysAndValues ...interface{})
	Errorf(msg string, keysAndValues ...interface{})
}

And cutomer logger can set for the client with the following options.

rest.WithLogger(&CustomLogger{})
grpc.WithLogger(&CustomLogger{})

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	// Send sends a request to raccoon with the message provided
	// and returns the request guid, response and error.
	Send([]*Event) (string, *Response, error)
}

type Event

type Event struct {
	Type string
	Data interface{}
}

type Response

type Response struct {
	Status   int32
	Code     int32
	SentTime int64
	Reason   string
	Data     map[string]string
}

Directories

Path Synopsis
examples
ws

Jump to

Keyboard shortcuts

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