micro

package module
v2.0.4 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2023 License: MIT Imports: 13 Imported by: 8

README

About GoMicro

Go-Micro is a set of lightweight Go microservice framework, including a large number of microservice related frameworks and tools, such as:

  • The communication protocol is based on the HTTP/gRPC through the definition of Protobuf.
  • Abstract transport layer support: HTTP / gRPC.
  • Powerful middleware design, support: Tracing (OpenTelemetry), Metrics (Prometheus is default), Recovery and more.
  • Registry interface able to be connected with various other centralized registries through plug-ins.
  • The standard log interfaces ease the integration of the third-party log libs.
  • Automatically support the selection of the content encoding with Accept and Content-Type.
  • Multiple data sources are supported for configurations and dynamic configurations (use atomic operations).
  • In the protocol of HTTP/gRPC, use the uniform metadata transfer method.
  • You can define errors in protos and generate enums with protoc-gen-errors.
  • You can define elasticsearch fields, queries and auto generate code with protoc-gen-es
  • You can define verification rules in Protobuf supported by the HTTP/gRPC service.

GoMicro is accessible, powerful, and provides tools required for large, robust applications.

License

The GoMicro framework is open-sourced software licensed under the MIT license.

Documentation

Index

Constants

View Source
const Release = "v2.0.4"

Release is the current micro version.

Variables

This section is empty.

Functions

func NewContext

func NewContext(ctx context.Context, s AppInfo) context.Context

NewContext returns a new Context that carries value.

Types

type App

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

App is an application components lifecycle manager.

func New

func New(opts ...Option) *App

New create an application lifecycle manager.

func (*App) Endpoint

func (a *App) Endpoint() []string

Endpoint returns endpoints.

func (*App) ID

func (a *App) ID() string

ID returns app instance id.

func (*App) Metadata

func (a *App) Metadata() map[string]string

Metadata returns service metadata.

func (*App) Name

func (a *App) Name() string

Name returns service name.

func (*App) Run

func (a *App) Run() error

Run executes all OnStart hooks registered with the application's Lifecycle.

func (*App) Stop

func (a *App) Stop() (err error)

Stop gracefully stops the application.

func (*App) Version

func (a *App) Version() string

Version returns app version.

type AppInfo

type AppInfo interface {
	ID() string
	Name() string
	Version() string
	Metadata() map[string]string
	Endpoint() []string
}

AppInfo is application context value.

func FromContext

func FromContext(ctx context.Context) (s AppInfo, ok bool)

FromContext returns the Transport value stored in ctx, if any.

type Option

type Option func(o *options)

Option is an application option.

func AfterStart

func AfterStart(fn func(context.Context) error) Option

AfterStart run funcs after app starts

func AfterStop

func AfterStop(fn func(context.Context) error) Option

AfterStop run funcs after app stops

func BeforeStart

func BeforeStart(fn func(context.Context) error) Option

BeforeStart run funcs before app starts

func BeforeStop

func BeforeStop(fn func(context.Context) error) Option

BeforeStop run funcs before app stops

func Context

func Context(ctx context.Context) Option

Context with service context.

func Endpoint

func Endpoint(endpoints ...*url.URL) Option

Endpoint with service endpoint.

func ID

func ID(id string) Option

ID with service id.

func Logger

func Logger(logger log.Logger) Option

Logger with service logger.

func Metadata

func Metadata(md map[string]string) Option

Metadata with service metadata.

func Name

func Name(name string) Option

Name with service name.

func Registrar

func Registrar(r registry.Registrar) Option

Registrar with service registry.

func RegistrarTimeout

func RegistrarTimeout(t time.Duration) Option

RegistrarTimeout with registrar timeout.

func Server

func Server(srv ...transport.Server) Option

Server with transport servers.

func Signal

func Signal(sigs ...os.Signal) Option

Signal with exit signals.

func StopTimeout

func StopTimeout(t time.Duration) Option

StopTimeout with app stop timeout.

func Version

func Version(version string) Option

Version with service version.

Jump to

Keyboard shortcuts

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