Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Cago ¶
type Cago struct {
// contains filtered or unexported fields
}
func New ¶
New create a new cago instance ctx 可以管理整个应用的生命周期,当ctx.Done()时,会传递到每一个组件,安全退出 cfg 配置文件,每一个组件都可以使用,通过 configs.NewConfig 去构建 应用启动时,会调用每一个组件的 Component.Start 方法,启动组件 应用停止时,会调用每一个组件的 Component.CloseHandle 方法,关闭组件 推荐链式调用的方式去使用 cago.New(ctx, cfg).Registry(component.Core()).RegistryCancel(mux.HTTP(api.Router)).Start()
func (*Cago) RegistryCancel ¶
func (r *Cago) RegistryCancel(component ComponentCancel) *Cago
RegistryCancel 注册cancel组件,cancel组件可以停止整个应用
type CloseHandle ¶
type CloseHandle func()
type Component ¶
type Component interface {
// Start 启动组件 会传入框架的context和配置文件
Start(ctx context.Context, cfg *configs.Config) error
// CloseHandle 关闭处理 当应用停止时,会调用该方法,停止组件
CloseHandle()
}
Component 组件接口
type ComponentCancel ¶
type ComponentCancel interface {
Component
// StartCancel 启动组件,会传入框架的context和配置文件,以及cancel方法
// 可以通过cancel方法停止整个应用
StartCancel(ctx context.Context, cancel context.CancelFunc, cfg *configs.Config) error
}
ComponentCancel 带cancel方法的组件 可以停止整个应用
type FuncComponent ¶
FuncComponent 函数式组件 适用于简单的组件 当你的组件不需要释放资源时,你可以只写一个函数,然后通过 FuncComponent 转换成组件 例如:
cago.FuncComponent(func(ctx context.Context, cfg *configs.Config) error {
return nil
})
func (FuncComponent) CloseHandle ¶
func (f FuncComponent) CloseHandle()
type FuncComponentCancel ¶
type FuncComponentCancel func(ctx context.Context, cancel context.CancelFunc, cfg *configs.Config) error
FuncComponentCancel 函数式带cancel方法的组件 适用于简单的组件,与 FuncComponent 的区别是多了一个cancel方法
func (FuncComponentCancel) CloseHandle ¶
func (f FuncComponentCancel) CloseHandle()
func (FuncComponentCancel) StartCancel ¶
func (f FuncComponentCancel) StartCancel(ctx context.Context, cancel context.CancelFunc, cfg *configs.Config) error
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
cago
command
|
|
|
database
|
|
|
examples
|
|
|
simple/cmd/app
command
|
|
|
simple/docs
Package docs GENERATED BY THE COMMAND ABOVE; DO NOT EDIT This file was generated by swaggo/swag at 2024-04-12 17:50:02.541948 +0800 CST m=+0.060448417
|
Package docs GENERATED BY THE COMMAND ABOVE; DO NOT EDIT This file was generated by swaggo/swag at 2024-04-12 17:50:02.541948 +0800 CST m=+0.060448417 |
|
simple/internal/repository/user_repo/mock
Package mock_user_repo is a generated GoMock package.
|
Package mock_user_repo is a generated GoMock package. |
|
internal
|
|
|
pkg
|
|
|
utils/testutils
一些用于测试的工具函数
|
一些用于测试的工具函数 |
|
server
|
|
Click to show internal directories.
Click to hide internal directories.