infra

package module
v0.0.24 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2021 License: Apache-2.0 Imports: 5 Imported by: 0

README

distill-infra

star fork

介绍

一种Go基础设施框架,启动过程类似于java的spring boot,然而逻辑加载和处理过程要强于前者。将各种基础设施封装于Starter组件之中,通过实现starter.go中的Starter接口,通过协程方式初始化各类基础设置中间件的集成。项目默认封装了toml配置、iris框架、casbin权限管理、jwt-go认证管理、xormplus持久框架、logrus日志引擎、以及整合了go-micro框架,可以采用etcdv3、k8s、consul等注册中心,当然也可以使用go-micro框架集成的熔断、限流等组件,作为微服务框架的基础设置层实现。可参考banyanhouse本人项目列表中的baixing项目,因本人工作繁忙,文档更新较慢,欢迎有志之士star或fork。

使用教程

  1. distill-base第一个基础web框架教程,结合distill-infra框架,且提供docker编译镜像,容器运行步骤。
  2. distill-db-tx集成了xormplus实现的一些事务操作场景
  3. distill-micro-http采用http协议构建的微服务
  4. distill-micro-grpc采用grpc协议构建的微服务
  5. distill-micro-grpc-hystrix远程grpc协议结合hystrix-go构建支持熔断调用的微服务
  6. 微服务教程后续更新...

安装教程

建议采用go.mod文件直接引用,即可使用本框架。

go mod tidy

go build

使用说明

  1. 在项目框架中提供了brun包,作为项目启动样例。
  2. 可以在项目中创建一个配置包,本项目样例在brun/boot目录中app.go文件中
  3. 将所使用到的基础设置Starter在此文件中进行配置,再将app.go所处的包引入到main.go文件中即可完成配置启动。

参与贡献

  1. 目前只有我一个人在做
  2. ...

码云特技

  1. 使用 Readme_XXX.md 来支持不同的语言,例如 Readme_en.md, Readme_zh.md
  2. 码云官方博客 blog.gitee.com
  3. 你可以 https://gitee.com/explore 这个地址来了解码云上的优秀开源项目
  4. GVP 全称是码云最有价值开源项目,是码云综合评定出的优秀开源项目
  5. 码云官方提供的使用手册 https://gitee.com/help
  6. 码云封面人物是一档用来展示码云会员风采的栏目 https://gitee.com/gitee-stars/

Documentation

Index

Constants

View Source
const (
	KeyProps     = "_conf"
	ContextProps = "_props"
)

Variables

View Source
var StarterRegister *starterRegister = &starterRegister{}

Functions

func Props added in v0.0.14

func Props(ctx context.Context) *conf.TomlConfig

func Register

func Register(starter Starter)

注册starter

func SetProps added in v0.0.14

func SetProps(ctx context.Context, conf *conf.TomlConfig) context.Context

func SortStarters

func SortStarters()

func StarterCancel added in v0.0.14

func StarterCancel() context.CancelFunc

Types

type BaseStarter

type BaseStarter struct {
}

默认的空实现,方便资源启动器的实现

func (*BaseStarter) Init

func (s *BaseStarter) Init(context.Context)

func (*BaseStarter) ListenStopSig added in v0.0.14

func (s *BaseStarter) ListenStopSig(ctx context.Context)

func (*BaseStarter) Priority

func (s *BaseStarter) Priority() int

func (*BaseStarter) PriorityGroup

func (s *BaseStarter) PriorityGroup() PriorityGroup

func (*BaseStarter) Setup

func (s *BaseStarter) Setup(context.Context)

func (*BaseStarter) Start

func (s *BaseStarter) Start(context.Context)

func (*BaseStarter) StartBlocking

func (s *BaseStarter) StartBlocking() bool

func (*BaseStarter) Stop

func (s *BaseStarter) Stop(context.Context)

type BootApplication

type BootApplication struct {
	IsTest bool
	// contains filtered or unexported fields
}

应用程序

func New

func New(conf *conf.TomlConfig) *BootApplication

构造系统

func (*BootApplication) Start

func (b *BootApplication) Start()

func (*BootApplication) Stop

func (e *BootApplication) Stop()

程序开始运行,开始接受调用

type PriorityGroup

type PriorityGroup int
const (
	SystemGroup         PriorityGroup = 30
	BasicResourcesGroup PriorityGroup = 20
	AppGroup            PriorityGroup = 10

	INT_MAX          = int(^uint(0) >> 1)
	DEFAULT_PRIORITY = 10000
)

type Starter

type Starter interface {
	//资源初始化和,通常把一些准备资源放在这里运行
	Init(context.Context)
	//资源的安装,所有启动需要的具备条件,使得资源达到可以启动的就备状态
	Setup(context.Context)
	//启动资源,达到可以使用的状态
	Start(context.Context)
	//说明该资源启动器开始启动服务时,是否会阻塞
	//如果存在多个阻塞启动器时,只有最后一个阻塞,之前的会通过goroutine来异步启动
	//所以,需要规划好启动器注册顺序
	StartBlocking() bool
	//资源停止:
	// 通常在启动时遇到异常时或者启用远程管理时,用于释放资源和终止资源的使用,
	// 通常要优雅的释放,等待正在进行的任务继续,但不再接受新的任务
	Stop(context.Context)
	PriorityGroup() PriorityGroup
	Priority() int
}

资源启动器,每个应用少不了依赖其他资源,比如数据库,缓存,消息中间件等等服务 启动器实现类,不需要实现所有方法,只需要实现对应的阶段方法即可,可以嵌入@BaseStarter 通过实现资源启动器接口和资源启动注册器,友好的管理这些资源的初始化、安装、启动和停止。 Starter对象注册器,所有需要在系统启动时需要实例化和运行的逻辑,都可以实现此接口 注意只有Start方法才能被阻塞,如果是阻塞Start(),同时StartBlocking()要返回true

func GetStarters

func GetStarters() []Starter

获取所有注册的starter

type Starters

type Starters []Starter

func (Starters) Len

func (s Starters) Len() int

func (Starters) Less

func (s Starters) Less(i, j int) bool

func (Starters) Swap

func (s Starters) Swap(i, j int)

Directories

Path Synopsis
apis
authentication
vo
app
common
core
verflag
Package verflag defines utility functions to handle command line flags related to version of Kubernetes.
Package verflag defines utility functions to handle command line flags related to version of Kubernetes.

Jump to

Keyboard shortcuts

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