/go-utils

Reusable GoLang utils

Primary LanguageGo

Go-Utils. Reusable GoLang utils.

Build Status

Table of Contents

  1. debug.go
  2. grace.go
  3. ticker.go
  4. config.go
  5. api.go
  6. server_group.go
  7. tracing.go
  8. checker.go
  9. vault.go
  10. json_formatter.go
  11. messagebus.go
  12. amqp-kit
  13. consul

Starting Pprof Server to a free port from a specified range. Prints all goroutine stacks to stdout

Package processes the low-level operating system call : syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP .

Creates a new ticker, which sends current time to its channel every second, minute, or hour after the specified delay. Wrap over standard time

A set of basic utilities for working with config files

A simple REST API server based on gorilla mux, go-kit handlers, and a standard http.Server.

ServerGroup allows to start several sg.Server objects and stop them, tracking errors.

HTTP client based on standart net/http client with additional method adding a Zipkin span to request.

Helper for execute series of tests

Helper for working with vault hashicorp

Implementation JSONFormatter of logrus with supporting additional fields for output

Handy wrapper for amqp Usage:

package main

import (
	"flag"
	"fmt"
	"log"

	"github.com/space307/go-utils/messagebus"
)

func main() {
	var mode string

	flag.StringVar(&mode, "mode", "", "a string var")
	flag.Parse()

	mb, err := messagebus.Dial("amqp://guest:guest@172.17.0.2:5672/")
	if err != nil {
		log.Fatal(err)
	}

	defer mb.Close()

	handler := func(key string, body []byte) error {
		log.Printf("[%s] %q", key, body)
		return nil
	}

	var (
		exchangeName = "test-exchange"
		queueName    = "test-queue"
	)

	switch mode {
	case "p":
		mb.SetName("producer")

		for i := 0; i < 5000; i++ {
			if err := mb.Produce(exchangeName, fmt.Sprintf("test.%d", i), []byte(fmt.Sprintf("body-%d", i))); err != nil {
				log.Printf("Produce error: %v", err)
			}
		}

	case "c":
		mb.SetName("consumer")

		if err = mb.Consume(exchangeName, queueName, []string{"test.*", "foo.*"}, handler); err != nil {
			log.Printf("%v", err)
		}

	default:
	}
}

AMQP wrapper in go-kit style

see test example for use: publisher_test.go

Consul package contains a wrapper for Consul API for simplicity registration a service in the local agent.