library

module
v1.3.5 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2024 License: MIT

README

之前的ioc

map形式,注册name:“interface"

如果掉用其方法,就是实现init,这样才调

现在的ioc

切片,只需要注册 name,version

如果掉用其方法,就是实现init,这样才调,但是这种方式只要name和version,比上面更复杂好用

app1 ioc1 是老的版本 map

app ioc 是新的版本 slice

补充业务异常

req := ioc.NewLoadConfigRequest()
req.ConfigFile.Enabled = true
req.ConfigFile.Path = "/Users/kade.chen/go12-project/sso/etc/application.toml"
ioc.DevelopmentSetup(req)

自动加载注册init所有ioc

补充细节 cookis业务报错 测试例子

更快到官网

git tag v1.3.5

git push -f https://gitee.com/go-kade/library.git v1.3.5

https://pkg.go.dev/gitee.com/go-kade/library/tree/v1.3.5

https://pkg.go.dev/gitee.com/go-kade/library@v1.3.5

备注:https://deps.dev/go/gitee.com%2Fgo-kade%2Flibrary/v1.0.1-0.20240201092113-6e4b7db5c891/versions 如果不知道版本可以从这里看

最新 13分钟同步完成 21分钟前 https://deps.dev/go/gitee.com%2Fgo-kade%2Flibrary/v1.2.1/versions 这个出来

_ "gitee.com/go-kade/library/ioc/config/cors"

_ "gitee.com/go-kade/library/ioc/apps/apidoc/restful"

想用apidoc得闲注入cors

_ "gitee.com/go-kade/library/ioc/apps/apidoc/restful" //依赖cors,不然访问会失败,里面只有apidoc
_ "gitee.com/go-kade/library/ioc/apps/health/restful"  
_ "gitee.com/go-kade/library/ioc/apps/metric/restful"  //promethus的指标暴露
_ "gitee.com/go-kade/library/ioc/config/cors"  //如果不加这个,跨域可能会有问题,另外apidoc也用不了

_ "gitee.com/go-kade/library/ioc/apps/apidoc/swaggo" gin
func main() {
	// 注册HTTP接口类
	ioc.Api().Registry(&HelloServiceApiHandler{})
	// 启动应用
	// req := ioc.NewLoadConfigRequest()
	// req.ConfigFile.Enabled = true
	// req.ConfigFile.Path = "/Users/kade.chen/go12-project/library/etc/application.toml"
	err := server.Run(context.Background(), nil)
	if err != nil {
		panic(err)
	}
}


type HelloServiceApiHandler struct {
	// 继承自Ioc对象
	ioc.ObjectImpl
}

// 模块的名称, 会作为路径的一部分比如: /mcube_service/api/v1/hello_module/
// 路径构成规则 <service_name>/<path_prefix>/<service_version>/<module_name>
// http://127.0.0.1:8080/default/api/v1/hello_module
func (h *HelloServiceApiHandler) Name() string {
	return "hello_module"
}

func (h *HelloServiceApiHandler) Version() string {
	return "v1"
}

// API路由
func (h *HelloServiceApiHandler) Registry(ws *restful.WebService) {
	///default/api/v1/hello_module/
	ws.Route(ws.GET("/").To(func(r *restful.Request, w *restful.Response) {
		w.WriteAsJson(map[string]string{
			"data": "hello mcube1111111",
		})
	}))
	//default/api/v1/hello_module/cc
	ws.Route(ws.GET("/cc").To(func(r *restful.Request, w *restful.Response) {
		w.WriteAsJson(map[string]string{
			"data": "hello mcube1111111",
		})
	}))
	//default/api/v1/hello_module/cc/111
	ws.Route(ws.GET("/cc/111").To(func(r *restful.Request, w *restful.Response) {
		w.WriteAsJson(map[string]string{
			"data": "hello mcube1111111",
		})
	}))
}

//自定义路由
func (i *SwaggerApiDoc) Meta() ioc.ObjectMeta {
	return DefaultObjectMeta1()
}

func DefaultObjectMeta1() ioc.ObjectMeta {
	return ioc.ObjectMeta{
		//		CustomPathPrefix: "/s", 必须要/号 http://127.0.0.1:8080/s
		CustomPathPrefix: "/swagger.json",
		// CustomPathPrefix: "/s",
		Extra: map[string]string{},
	}
}

Jump to

Keyboard shortcuts

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