Skip to content

Commit

Permalink
update framework examples
Browse files Browse the repository at this point in the history
  • Loading branch information
cg33 committed Dec 10, 2019
1 parent 329e8cf commit 69467e5
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 11 deletions.
5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
.DS_Store
demo/config.json
demo/config
demo/uploads
demo/deploy.yml
demo/hosts
demo/go-admin
demo/Makefile
demo/deploy.retry
examples/gin/uploads/
vendor/**
!vendor/vendor.json
logs
adm/build
template/login/assets/login
template/login/assets/login
uploads
16 changes: 12 additions & 4 deletions examples/beego/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
_ "github.com/GoAdminGroup/go-admin/modules/db/drivers/mysql"
"github.com/GoAdminGroup/go-admin/template"
"github.com/GoAdminGroup/go-admin/template/chartjs"
"github.com/GoAdminGroup/themes/adminlte"
_ "github.com/GoAdminGroup/themes/adminlte"

"github.com/GoAdminGroup/go-admin/engine"
Expand Down Expand Up @@ -36,10 +37,15 @@ func main() {
Driver: config.DriverMysql,
},
},
UrlPrefix: "admin",
IndexUrl: "/",
Debug: true,
Language: language.CN,
Store: config.Store{
Path: "./uploads",
Prefix: "uploads",
},
UrlPrefix: "admin",
IndexUrl: "/",
Debug: true,
Language: language.CN,
ColorScheme: adminlte.ColorschemeSkinBlack,
}

adminPlugin := admin.NewAdmin(datamodel.Generators).AddDisplayFilterXssJsFilter()
Expand Down Expand Up @@ -70,6 +76,8 @@ func main() {
//
// eng.AddConfigFromJSON("../datamodel/config.json")

beego.SetStaticPath("/uploads", "uploads")

if err := eng.AddConfig(cfg).AddPlugins(adminPlugin, examplePlugin).Use(app); err != nil {
panic(err)
}
Expand Down
27 changes: 27 additions & 0 deletions examples/chi/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ import (
"github.com/GoAdminGroup/themes/adminlte"
"github.com/go-chi/chi"
"net/http"
"os"
"path/filepath"
"strings"
)

func main() {
Expand Down Expand Up @@ -78,6 +81,10 @@ func main() {
panic(err)
}

workDir, _ := os.Getwd()
filesDir := filepath.Join(workDir, "uploads")
FileServer(r, "/uploads", http.Dir(filesDir))

// you can custom your pages like:

r.Get("/admin", func(writer http.ResponseWriter, request *http.Request) {
Expand All @@ -88,3 +95,23 @@ func main() {

_ = http.ListenAndServe(":3333", r)
}

// FileServer conveniently sets up a http.FileServer handler to serve
// static files from a http.FileSystem.
func FileServer(r chi.Router, path string, root http.FileSystem) {
if strings.ContainsAny(path, "{}*") {
panic("FileServer does not permit URL parameters.")
}

fs := http.StripPrefix(path, http.FileServer(root))

if path != "/" && path[len(path)-1] != '/' {
r.Get(path, http.RedirectHandler(path+"/", 301).ServeHTTP)
path += "/"
}
path += "*"

r.Get(path, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fs.ServeHTTP(w, r)
}))
}
10 changes: 8 additions & 2 deletions examples/echo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,12 @@ func main() {
},
UrlPrefix: "admin",
IndexUrl: "/",
Debug: true,
Language: language.CN,
Store: config.Store{
Path: "./uploads",
Prefix: "uploads",
},
Debug: true,
Language: language.CN,
}

adminPlugin := admin.NewAdmin(datamodel.Generators).AddDisplayFilterXssJsFilter()
Expand Down Expand Up @@ -73,6 +77,8 @@ func main() {
panic(err)
}

e.Static("/uploads", "./uploads")

// you can custom your pages like:

e.GET("/admin", func(context echo.Context) error {
Expand Down
10 changes: 8 additions & 2 deletions examples/fasthttp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,12 @@ func main() {
},
UrlPrefix: "admin",
IndexUrl: "/",
Debug: true,
Language: language.CN,
Store: config.Store{
Path: "./uploads",
Prefix: "uploads",
},
Debug: true,
Language: language.CN,
}

adminPlugin := admin.NewAdmin(datamodel.Generators).AddDisplayFilterXssJsFilter()
Expand Down Expand Up @@ -74,6 +78,8 @@ func main() {
panic(err)
}

router.ServeFiles("/uploads", "./uploads")

router.GET("/admin", func(ctx *fasthttp.RequestCtx) {
eng.Content(ctx, func(ctx interface{}) (types.Panel, error) {
return datamodel.GetContent()
Expand Down
2 changes: 2 additions & 0 deletions examples/gf/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ func main() {
panic(err)
}

s.AddStaticPath("uploads", "./uploads")

// customize your pages

s.BindHandler("GET:/admin", func(ctx *ghttp.Request) {
Expand Down
2 changes: 2 additions & 0 deletions examples/gorilla/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ func main() {
panic(err)
}

app.PathPrefix("/uploads/").Handler(http.StripPrefix("/uploads/", http.FileServer(http.Dir("./uploads"))))

app.Handle("/admin", http.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) {
eng.Content(ada.Context{Request: request, Response: writer}, func(ctx interface{}) (types.Panel, error) {
return datamodel.GetContent()
Expand Down
6 changes: 6 additions & 0 deletions examples/iris/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ func main() {
panic(err)
}

app.HandleDir("/uploads", "./uploads", iris.DirOptions{
IndexName: "/index.html",
Gzip: false,
ShowList: false,
})

// you can custom your pages like:

app.Get("/admin", func(context iris.Context) {
Expand Down

0 comments on commit 69467e5

Please sign in to comment.