建议的Go语言管理仪表板功能:

huangapple go评论156阅读模式
英文:

Suggestions for admin dashboard in golang

问题

我正在使用gobuffalo框架创建一个带有Postgres数据库的网站,并且我正在尝试找一个好的管理面板来配套使用。像Rails的ActiveAdmin这样的东西会很棒。有人有什么建议吗?

英文:

I am using a gobuffalo framework to create a website with a postgres database, and I am trying to find a good admin dashboard to accompany it. Something like Rail's ActiveAdmin would be awesome. Does anyone have any suggestions?

答案1

得分: 5

我最终使用qor/admin来生成仪表板。它已经设置好了视图。我只需要告诉qor我想要显示哪些模型的代码。对于其他想在gobuffalo.io中实现这一点的人,以下是如何生成路由的方法:

func App() *buffalo.App {
    if app == nil {
        app = buffalo.Automatic(buffalo.Options{
            Env:         ENV,
            SessionName: "_liam_session",
        })

        app.GET("/", HomeHandler)
        app.ANY("/admin/{path:.+}", buffalo.WrapHandler(http.StripPrefix("/admin", Other())))
        app.ServeFiles("/assets", packr.NewBox("../public/assets"))
    }
    return app
}

func Other() http.Handler {
    f := func(res http.ResponseWriter, req *http.Request) {
        fmt.Fprintln(res, req.URL.String())
        fmt.Fprintln(res, req.Method)
    }
    mux := mux.NewRouter()
    mux.HandleFunc("/foo", f).Methods("GET")
    mux.HandleFunc("/bar", f).Methods("DELETE")
    return mux
}
英文:

I ended up using qor/admin to generate the dashboard. It came with views that were already setup. The only code I needed was to tell qor which models I wanted to show. For anyone else trying to implement this in gobuffalo.io, here is how you can generate the routes

func App() *buffalo.App {
	if app == nil {
		app = buffalo.Automatic(buffalo.Options{
			Env:         ENV,
			SessionName: "_liam_session",
		})

		app.GET("/", HomeHandler)
		app.ANY("/admin/{path:.+}", buffalo.WrapHandler(http.StripPrefix("/admin", Other())))
		app.ServeFiles("/assets", packr.NewBox("../public/assets"))
	}
	return app
}

func Other() http.Handler {
	f := func(res http.ResponseWriter, req *http.Request) {
		fmt.Fprintln(res, req.URL.String())
		fmt.Fprintln(res, req.Method)
	}
	mux := mux.NewRouter()
	mux.HandleFunc("/foo", f).Methods("GET")
	mux.HandleFunc("/bar", f).Methods("DELETE")
	return mux
}

答案2

得分: 2

我使用模板来实现这个功能,效果很好。你可以快速生成视图、处理程序和模型,还可以使用基本的管理视图来进行 CRUD 操作,非常方便。当然,对于每个管理视图,你可能需要进行一定程度的自定义,但作为起点,它非常有效。

我正在使用的工具是 这个(如果你使用过 Rails,应该会很熟悉),你也可以使用 go generate(用于代码)、类似 genny 的工具,或者使用 text/template 自己编写解决方案来生成所需的代码。我已经在几个项目中使用了这种方法,如果你发现自己需要稍后自定义仪表板,我推荐使用这种方法。大多数应用程序对于每个资源(创建、更新、删除、索引)都有一定数量的样板代码。

英文:

I use templates for this and it works well. You can generate the views and potentially the handlers and model with basic admin views for CRUD actions very quickly, which is nice. Obviously for each admin view you're going to want to customise it to some extent but as a starting point it works very well.

This is the tool I'm using (if you've used rails it should be familiar), you should also be able to knock something together with go generate (for code), a tool like genny, or just your own solution using text/template to output what you need. I've used this approach on a few projects now, I recommend if you find yourself creating dashboards which then need to be customised later. Most apps have a certain amount of boilerplate for each resource (create, update, delete, index).

huangapple
  • 本文由 发表于 2017年8月21日 22:50:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/45800136.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定