gaia

package module
v1.11.0 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2024 License: MIT Imports: 13 Imported by: 0

README

Gaia

Gaia[ˈɡaɪə] 一个轻量级gRPC业务框架

安装 protoc

$ go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
$ go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest

编译

protoc --go_out=. --go_opt=paths=source_relative \
    --go-grpc_out=. --go-grpc_opt=paths=source_relative \
    helloworld/helloworld.proto

感谢

Documentation

Index

Constants

View Source
const (
	Name    = "Gaia"
	Version = "v1.10.0"
)

Name and Version info of this framework, used for statistics and debug

Variables

This section is empty.

Functions

func Apply

func Apply(opts ...Option) *options

func NewContext

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

NewContext returns a new Context that carries value.

Types

type AppInfo

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

func FromContext

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

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

type Gaia

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

func New

func New(opts ...Option) *Gaia

New create an application lifecycle manager.

func (*Gaia) Endpoint

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

Endpoint returns endpoints.

func (*Gaia) ID

func (a *Gaia) ID() string

ID returns app instance id.

func (*Gaia) Metadata

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

Metadata returns service metadata.

func (*Gaia) Name

func (a *Gaia) Name() string

Name returns service name.

func (*Gaia) Run

func (a *Gaia) Run() error

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

func (*Gaia) Stop

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

Stop gracefully stops the application.

func (*Gaia) Version

func (a *Gaia) Version() string

Version returns app version.

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 WithContext

func WithContext(ctx context.Context) Option

WithContext with a context

func WithEndpoint

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

WithEndpoint with service endpoint.

func WithID

func WithID(id string) Option

WithID with app id

func WithLogger

func WithLogger(logger log.Logger) Option

WithLogger .

func WithMetadata

func WithMetadata(md map[string]string) Option

WithMetadata with service metadata.

func WithName

func WithName(name string) Option

WithName .

func WithRegistry

func WithRegistry(r registry.Registry) Option

WithRegistry with service registry.

func WithRegistryTimeout

func WithRegistryTimeout(t time.Duration) Option

WithRegistryTimeout with registrar timeout.

func WithServer

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

WithServer with a server , http or grpc

func WithSignal

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

WithSignal with some system signal

func WithStopTimeout

func WithStopTimeout(t time.Duration) Option

WithStopTimeout with app stop timeout.

func WithVersion

func WithVersion(version string) Option

WithVersion with a version

Jump to

Keyboard shortcuts

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