dove

package module
v1.2.10 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2023 License: MIT Imports: 11 Imported by: 0

README

dove

应用程序生命周期服务管理框架。

安装

go get -u github.com/camry/dove

使用

package main

import (
    "log"
    "context"

    "github.com/camry/dove"
    "github.com/camry/dove/server/gcron"
    "github.com/camry/dove/server/ghttp"
    "github.com/camry/dove/server/grpc"
    "github.com/camry/dove/server/gtcp"
    "github.com/camry/dove/server/gudp"
    ggtcp "github.com/camry/g/gnet/gtcp"
    ggudp "github.com/camry/g/gnet/gudp"
)

func main() {
    hs := ghttp.NewServer()
    gs := grpc.NewServer()
    gc := gcron.NewServer()
    tcp := gtcp.NewServer(gtcp.Handler(func(conn *ggtcp.Conn) {
    }))
    udp := gudp.NewServer(gudp.Handler(func(conn *ggudp.Conn) {
    }))
    app := dove.New(
        dove.Name("dove"),
        dove.Version(dove.Release),
        dove.Server(hs, gs, gc, tcp, udp),
        dove.BeforeStart(func(_ context.Context) error {
            log.Println("BeforeStart...")
            return nil
        }),
        dove.BeforeStop(func(_ context.Context) error {
            log.Println("BeforeStop...")
            return nil
        }),
        dove.AfterStart(func(_ context.Context) error {
            log.Println("AfterStart...")
            return nil
        }),
        dove.AfterStop(func(_ context.Context) error {
            log.Println("AfterStop...")
            return nil
        }),
    )
    if err := app.Run(); err != nil {
        log.Fatal(err)
    }
}

License

Dove 框架开源许可证 MIT LICENSE

致谢

以下项目对 Dove 框架的设计产生了特别的影响。

  • go-kratos/kratos Kratos is a microservice-oriented governance framework implemented by golang.

Documentation

Index

Constants

View Source
const Release = "v1.2.2"

Variables

This section is empty.

Functions

func NewContext

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

NewContext 返回一个带有值的新上下文。

Types

type App

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

App 应用程序组件生命周期管理器。

func New

func New(opts ...Option) *App

New 创建应用生命周期管理器。

func (*App) ID

func (a *App) ID() string

ID 返回服务实例ID。

func (*App) Name

func (a *App) Name() string

Name 返回服务名称。

func (*App) Run

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

Run 执行应用程序生命周期中注册的所有服务。

func (*App) Stop

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

Stop 优雅的停止应用程序。

func (*App) Version

func (a *App) Version() string

Version 返回服务版本号。

type AppInfo

type AppInfo interface {
	ID() string
	Name() string
	Version() string
}

AppInfo 应用程序上下文值接口。

func FromContext

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

FromContext 返回存储在 ctx 中的传输值(如果有)。

type Option

type Option func(o *option)

Option 定义一个应用程序选项类型。

func AfterStart added in v1.2.2

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

AfterStart 应用启动后执行此 funcs。

func AfterStop added in v1.2.2

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

AfterStop 应用停止后执行此 funcs。

func BeforeStart added in v1.2.2

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

BeforeStart 应用启动前执行此 funcs。

func BeforeStop added in v1.2.2

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

BeforeStop 应用停止前执行此 funcs。

func Context

func Context(ctx context.Context) Option

Context 配置服务上下文。

func ID

func ID(id string) Option

ID 配置服务ID。

func Logger

func Logger(logger glog.Logger) Option

Logger 配置日志记录器。

func Name

func Name(name string) Option

Name 配置服务名称。

func Server

func Server(srv ...server.Server) Option

Server 配置服务器。

func Signal added in v1.2.2

func Signal(signals ...os.Signal) Option

Signal 配置服务信号。

func StopTimeout

func StopTimeout(t time.Duration) Option

StopTimeout 配置应用停止超时时间(单位:秒)。

func Version

func Version(version string) Option

Version 配置服务版本。

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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