Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于 gin 的使用 #466

Closed
phpcyy opened this issue May 10, 2023 · 3 comments · Fixed by #469
Closed

关于 gin 的使用 #466

phpcyy opened this issue May 10, 2023 · 3 comments · Fixed by #469

Comments

@phpcyy
Copy link
Contributor

phpcyy commented May 10, 2023

以下代码应该就可以使用 gin 了,没必要在底层引入 gin 吧,或者你看看有啥问题:

func main() {
	mux := &tars.TarsHttpMux{}

	e := gin.Default()
	e.GET("/hello", func(context *gin.Context) {
		context.JSON(200, gin.H{
			"message": "Hello World",
		})
	})
	e.GET("/api/ping", func(context *gin.Context) {
		context.JSON(200, gin.H{
			"message": "pong",
		})
	})
	for _, info := range e.Routes() {
		mux.Handle(info.Path, e.Handler())
	}
	serverConfig := tars.GetServerConfig()
	objName := serverConfig.App + "." + serverConfig.Server + ".HttpObj"
	tars.AddHttpServant(mux, objName)
        tars.Run()
}

新开个项目用了最新的 TarsGo,一看好家伙,好多依赖啊,还有些有安全问题,再一看全是 gin 导致的引入。

image
@phpcyy
Copy link
Contributor Author

phpcyy commented May 10, 2023

又看了下,Path 中有参数的话会有问题,可这如果不想用 gin 的话白白引入了这么多的依赖

@lbbniu
Copy link
Collaborator

lbbniu commented May 10, 2023

有更好的解耦方法吗? 欢迎pr

@lbbniu
Copy link
Collaborator

lbbniu commented May 23, 2023

又看了下,Path 中有参数的话会有问题,可这如果不想用 gin 的话白白引入了这么多的依赖

上面方法,参数路径还能使用吗?

@lbbniu lbbniu linked a pull request Jun 1, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants