ms

package module
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2019 License: MIT Imports: 25 Imported by: 0

README

ms

micro service build kit

Environment Variables

Bind Address

  • BIND_GRPC, bind address for grpc, default to 0.0.0.0:5000
  • BIND_DEBUG, bind address for expvar, pprof and prometheus, default to 0.0.0.0:6060

Logging

  • LOG_VERBOSE, whether zerolog debug level should be enabled
  • LOG_PLAIN, whether using zerolog console writer
  • LOG_COLOR, whether zerolog color output should be enabled

Concurrency

  • CONCURRENCY, concurrency limiter for both grpc and http, default to 128

Usage

package main

import "go.guoyk.net/ms"

func main() {
	ms.Main(&ms.Spec{
		Configure: func(opts *ms.Options) {
			return
		},
		Setup: func() error {
			log.Info().Msg("setup")
			go testGRPC()
			return nil
		},
		Build: func(s *grpc.Server) {
			RegisterTestServer(s, &testServer{})
			return
		},
		HealthCheck: func() error {
			return nil
		},
	})
}

Credits

Guo Y.K., MIT License

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EnvBool

func EnvBool(key string, defaultValue bool) bool

func EnvInt64

func EnvInt64(key string, defaultValue int64) int64

func EnvStr

func EnvStr(key string, defaultValue string) string

func LoadOptionsFromEnv added in v1.4.0

func LoadOptionsFromEnv(opts *Options)

func Main

func Main(spec Spec)

func Run added in v1.3.0

func Run(ctx context.Context, opts Options, spec Spec) (err error)

Types

type Options

type Options struct {
	Check bool
	Bind  struct {
		GRPC  string
		Debug string
	}
	Concurrency int64
	Log         struct {
		Plain   bool
		Color   bool
		Verbose bool
	}
}

type Spec

type Spec interface {
	Setup(opts Options) error

	Register(server *grpc.Server)

	BeforeStart() error
	AfterStart()

	BeforeStop()
	AfterStop()

	Check() bool
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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