Serge Bazanski | 3fd70d8 | 2018-10-14 08:12:46 -0700 | [diff] [blame] | 1 | Mirko, the HSWAW microservice helper library |
| 2 | ============================================ |
| 3 | |
| 4 | Wanna write a Go microservice for HSWAW? Can't be arsed to copy paste code? This is the library for you! |
| 5 | |
| 6 | Usage (dev) |
| 7 | ----------- |
| 8 | |
| 9 | package main |
| 10 | |
| 11 | import ( |
Serge Bazanski | c981e57 | 2018-10-25 12:12:35 +0100 | [diff] [blame] | 12 | "code.hackerspace.pl/hscloud/go/mirko" |
Serge Bazanski | 3fd70d8 | 2018-10-14 08:12:46 -0700 | [diff] [blame] | 13 | ) |
| 14 | |
| 15 | func main() { |
| 16 | m := mirko.New() |
| 17 | |
| 18 | // setup/checks before TCP ports are opened... |
| 19 | // ... |
| 20 | |
| 21 | if err := m.Listen(); err != nil { |
| 22 | glog.Exitf("Listen(): %v", err) |
| 23 | } |
| 24 | |
| 25 | // register your gRPC and http handlers... |
| 26 | // (relfection and basic debug http is automatically registered) |
| 27 | // pb.RegisterFooServer(m.GRPC(), s) |
| 28 | // m.HTTPMux().HandleFunc("/debug/foo", fooHandler) |
| 29 | |
| 30 | if err := m.Serve(); err != nil { |
| 31 | glog.Exitf("Serve(): %v", err) |
| 32 | } |
| 33 | |
| 34 | // start any other background processing... |
Serge Bazanski | 4f7ee51 | 2018-10-14 18:20:59 +0100 | [diff] [blame] | 35 | // (you can use m.Context() to get a context that will get |
| 36 | // canceled when the service is about to shut down) |
Serge Bazanski | 3fd70d8 | 2018-10-14 08:12:46 -0700 | [diff] [blame] | 37 | |
Serge Bazanski | 4f7ee51 | 2018-10-14 18:20:59 +0100 | [diff] [blame] | 38 | <-m.Done() |
Serge Bazanski | 3fd70d8 | 2018-10-14 08:12:46 -0700 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | Usage (running) |
| 42 | --------------- |
| 43 | |
| 44 | The following flags are automatically registered: |
| 45 | |
Serge Bazanski | 2a6175c | 2018-10-14 08:49:28 -0700 | [diff] [blame] | 46 | - `-listen_address` (default: `127.0.0.1:4200`): where to listen for gRPC requests |
| 47 | - `-debug_address` (default: `127.0.0.1:4201`): where to listen for debug HTTP requests |
Serge Bazanski | 446c9e1 | 2018-10-14 17:06:09 +0100 | [diff] [blame] | 48 | - `-debug_allow_all` (default: false): whether to allow all IP address (vs. localhost) to connect to debug endpoint |
Serge Bazanski | 3fd70d8 | 2018-10-14 08:12:46 -0700 | [diff] [blame] | 49 | |
Serge Bazanski | 3fd70d8 | 2018-10-14 08:12:46 -0700 | [diff] [blame] | 50 | The following debug HTTP handlers are installed: |
| 51 | |
Serge Bazanski | 8fab2be | 2018-10-25 23:37:37 +0200 | [diff] [blame] | 52 | - `/debug/status`: show the statusz page |
Serge Bazanski | 3fd70d8 | 2018-10-14 08:12:46 -0700 | [diff] [blame] | 53 | - `/debug/requests`: show the [net/trace](https://godoc.org/golang.org/x/net/trace) page (including gRPC traces) |
| 54 | |