mirko

package
v0.0.0-...-8887655 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2020 License: ISC Imports: 27 Imported by: 6

README

Mirko, the HSWAW microservice helper library
============================================

Wanna write a Go microservice for HSWAW? Can't be arsed to copy paste code? This is the library for you!

Usage (dev)
-----------

    package main

    import (
        "code.hackerspace.pl/hscloud/go/mirko"
    )

    func main() {
        m := mirko.New()

        // setup/checks before TCP ports are opened...
        // ...

        if err := m.Listen(); err != nil {
            glog.Exitf("Listen(): %v", err)
        }

        // register your gRPC and http handlers...
        // (relfection and basic debug http is automatically registered)
        // pb.RegisterFooServer(m.GRPC(), s)
        // m.HTTPMux().HandleFunc("/debug/foo", fooHandler)

        if err := m.Serve(); err != nil {
            glog.Exitf("Serve(): %v", err)
        }

        // start any other background processing...
        // (you can use m.Context() to get a context that will get
        // canceled when the service is about to shut down)

        <-m.Done()
    }

Usage (running)
---------------

The following flags are automatically registered:

 - `-listen_address` (default: `127.0.0.1:4200`): where to listen for gRPC requests
 - `-debug_address` (default: `127.0.0.1:4201`): where to listen for debug HTTP requests
 - `-debug_allow_all` (default: false): whether to allow all IP address (vs. localhost) to connect to debug endpoint

The following debug HTTP handlers are installed:

 - `/debug/status`: show the statusz page
 - `/debug/requests`: show the [net/trace](https://godoc.org/golang.org/x/net/trace) page (including gRPC traces)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewMigrationsFromBazel

func NewMigrationsFromBazel(data map[string][]byte) (source.Driver, error)

func Trace

func Trace(ctx context.Context, f string, args ...interface{})

Trace logs debug information to either a context trace (if present) or stderr (if not)

func TraceErrorf

func TraceErrorf(ctx context.Context, f string, args ...interface{})

func TraceInfof

func TraceInfof(ctx context.Context, f string, args ...interface{})

func TraceSQL

func TraceSQL(driver driver.Driver, wrapped string)

func TraceWarningf

func TraceWarningf(ctx context.Context, f string, args ...interface{})

Types

type Mirko

type Mirko struct {
	// contains filtered or unexported fields
}

func New

func New() *Mirko

func (*Mirko) Address

func (m *Mirko) Address() net.IP

Address returns a linkable address where this service is running, sans port. If running within kubernetes, this will return the pod IP. Otherwise, this will guess the main, 'external' IP address of the machine it's running on. On failures, returns loopback address.

func (*Mirko) Context

func (m *Mirko) Context() context.Context

Context returns a background microservice context that will be canceled when the service is shut down

func (*Mirko) Done

func (m *Mirko) Done() <-chan struct{}

Done() returns a channel that will emit a value when the service is shut down. This should be used in the main() function instead of a select{} call, to allow the background context to be canceled fully.

func (*Mirko) GRPC

func (m *Mirko) GRPC() *grpc.Server

GRPC returns the microservice's grpc.Server object

func (*Mirko) HTTPMux

func (m *Mirko) HTTPMux() *http.ServeMux

HTTPMux returns the microservice's debug HTTP mux

func (*Mirko) Listen

func (m *Mirko) Listen() error

func (*Mirko) Serve

func (m *Mirko) Serve() error

Serve starts serving HTTP and gRPC requests

Directories

Path Synopsis
tests

Jump to

Keyboard shortcuts

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