svc

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: May 19, 2022 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultServiceName = filepath.Base(os.Args[0])

Functions

func CLICmd

func CLICmd(name string, opts ...OptFunc) *cli.Command

func FlagsAndAction

func FlagsAndAction(optsargs ...OptFunc) ([]cli.Flag, func(c *cli.Context) error, *cliopts)

func MustStart

func MustStart(opts ...OptFunc) <-chan error

func Run

func Run(opts ...OptFunc)

func RunCLI

func RunCLI(name string, opts ...OptFunc)

func SetVersion added in v0.1.1

func SetVersion(v *Version)

func Start

func Start(opts ...OptFunc) (<-chan error, error)

Start the service. Returns a channel for asynchronous error handling, for example in case of a failure of the GRPC server itself.

The startup is done in the following order: 1. Configuration loading (both user specified and service); 2. Log initializations. 3. Call user Init functions. 4. If -setup is specified, call user Setup functions. 5. If -exit-before-start is not specified, call user Start functions.

Types

type CLIOptFunc

type CLIOptFunc func(*cliopts)

func WithCLIApp

func WithCLIApp(f func(*cli.App)) CLIOptFunc

func WithCLICommand

func WithCLICommand(cmd *cli.Command) CLIOptFunc

func WithCLIFlags

func WithCLIFlags(flags []cli.Flag) CLIOptFunc

func WithCLIPreaction

func WithCLIPreaction(f func(c *cli.Context) error) CLIOptFunc

type Component

type Component struct {
	Name                      string
	Init, Setup, Start, Ready interface{}
	Disabled                  bool
}

A component is a grouping of init/setup/start record that conceptually belong to a specific component with a name.

type Flags

type Flags struct {
	ConfigPath                                      string
	Enables, Disables, Onlys, Excepts               []string
	Setup, HelpConfig, PrintConfig, ExitBeforeStart bool
}

type GRPCAddr

type GRPCAddr net.Addr

type GRPCOptions

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

Specified GRPC Server Options for the server. Can only be used by the Init phase. Can be used, for example, to add interceptors by components.

func (*GRPCOptions) Add

func (g *GRPCOptions) Add(opts ...grpc.ServerOption)

type OptFunc

type OptFunc func(*opts)

func Provide

func Provide(p interface{}) OptFunc

Explicitly provide a new provider before initialization.

func WithCLIOptions

func WithCLIOptions(fs ...CLIOptFunc) OptFunc

func WithComponent

func WithComponent(comps ...Component) OptFunc

func WithConfig

func WithConfig(cfg interface{}) OptFunc

Load cfg from environment using envconfig before anything else.

func WithDefaultDisable

func WithDefaultDisable(ns ...string) OptFunc

Disable components by default unless enabled from cmdline.

func WithFlags

func WithFlags(f *Flags) OptFunc

Replace command line flags with Flags.

func WithGRPC

func WithGRPC(enabled bool) OptFunc

func WithHTTP

func WithHTTP(enabled bool) OptFunc

func WithInit

func WithInit(n string, f interface{}) OptFunc

Call the init function f after log is initialized and config is loaded.

func WithLogger

func WithLogger(l func() L.L) OptFunc

func WithName

func WithName(name string) OptFunc

Set service name, the executable name by default.

func WithReady

func WithReady(n string, f interface{}) OptFunc

Call the ready function f after everything else.

func WithSetup

func WithSetup(n string, f interface{}) OptFunc

Call the setup function f after init but before start. This is done only if -setup is specified.

func WithStart

func WithStart(n string, f interface{}) OptFunc

Call the start function f to start things up after init and setup. Additional providers available for start functions: *mux.Router, *grpc.Server.

type Providers

type Providers struct{ Vs []interface{} }

func (*Providers) Add

func (p *Providers) Add(v ...interface{})

func (*Providers) Get

func (p *Providers) Get(dst interface{}) bool

type SvcCfg

type SvcCfg struct {
	Log       Z.Config `envconfig:"LOG" json:"log"`
	HTTP      httpCfg  `envconfig:"HTTP" json:"http"`
	GRPC      grpcCfg  `envconfig:"GRPC" json:"grpc"`
	PprofPort int      `envconfig:"PPROF_PORT" json:"pprof_port"`
}

type Version added in v0.1.1

type Version struct{ Version, Commit, Date string }

func GetVersion added in v0.1.1

func GetVersion() *Version

func (Version) Any added in v0.1.1

func (v Version) Any() bool

func (Version) String added in v0.1.1

func (v Version) String() string

Jump to

Keyboard shortcuts

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