gowalk

package module
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2022 License: MIT Imports: 13 Imported by: 0

README

gowalk

关于

gowalk 一个简单易用的Golang后端开发框架,开箱即用,通过加载组件获取数据库等功能。

名字来源 :gowalk 意为去散步,希望gowalk可以像散步一样足够自由与灵活。

组件

开发中,持续更新

使用

  1. 框架约定在当前目录下加载名为config.yml的配置文件
  2. 框架提供了Component接口Logger接口Server接口,开发者可以自定义这些功能。
  3. 示例
type greeter struct {
    name string
}

// 实现component接口
func (g *greeter) Run() error {
    logk.Infof("hello, %s", g.name)
    return nil
}

func (g *greeter) Name() string {
    return "greeter"
}

var _ gowalk.Component = (*greeter)(nil)

func main() {
    // 加载组件
    _ = gowalk.Run(&greeter{name: "gowalk"})
    
    g, err := gowalk.GetComponent("greeter")
    if err != nil {
        logk.Fatal(err)
    }
    logk.Infof("greeter: %#v", g)
}

示例源码

MIT License

Copyright (c) 2022 cyj19

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddAndLoadComponents

func AddAndLoadComponents(args ...Component) error

AddAndLoadComponents 添加并加载指定组件

func AddComponents

func AddComponents(args ...Component)

AddComponents 添加组件

func LoadAllComponents

func LoadAllComponents() error

LoadAllComponents 加载全部组件

func Run

func Run(args ...Component) error

Types

type App

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

func New

func New(opts ...Option) *App

func (*App) Run

func (a *App) Run() error

Run 运行服务

type Component

type Component interface {
	Run() error   // 组件初始化
	Name() string // 获取组件名称
}

Component 组件接口

func GetComponent

func GetComponent(key string) (Component, error)

GetComponent 获取指定组件实例

type Option

type Option func(o *option)

func Context

func Context(ctx context.Context) Option

func ID

func ID(id string) Option

func Metadata

func Metadata(md map[string]interface{}) Option

func Name

func Name(name string) Option

func Servers

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

func Signal

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

func StopTimeout

func StopTimeout(t time.Duration) Option

func Version

func Version(version string) Option

Directories

Path Synopsis
examples
tcp
udp

Jump to

Keyboard shortcuts

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