mirror of
https://github.com/ngoduykhanh/wireguard-ui.git
synced 2025-04-21 20:12:33 +03:00
Fix rice build
This commit is contained in:
parent
d428bfe6f4
commit
8ea0ee3ca5
3 changed files with 15 additions and 18 deletions
|
@ -23,4 +23,5 @@ docker-compose*
|
||||||
|
|
||||||
# App data & bin
|
# App data & bin
|
||||||
db
|
db
|
||||||
|
assets
|
||||||
wireguard-ui
|
wireguard-ui
|
12
main.go
12
main.go
|
@ -2,13 +2,12 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
rice "github.com/GeertJohan/go.rice"
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"github.com/GeertJohan/go.rice"
|
|
||||||
"github.com/ngoduykhanh/wireguard-ui/handler"
|
"github.com/ngoduykhanh/wireguard-ui/handler"
|
||||||
"github.com/ngoduykhanh/wireguard-ui/router"
|
"github.com/ngoduykhanh/wireguard-ui/router"
|
||||||
"github.com/ngoduykhanh/wireguard-ui/util"
|
"github.com/ngoduykhanh/wireguard-ui/util"
|
||||||
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -18,11 +17,14 @@ func main() {
|
||||||
fmt.Print("Cannot init database: ", err)
|
fmt.Print("Cannot init database: ", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// the file server for rice. "assets" is the folder where the files come from.
|
// create rice box for embedded template
|
||||||
|
tmplBox := rice.MustFindBox("templates")
|
||||||
|
|
||||||
|
// rice file server for assets. "assets" is the folder where the files come from.
|
||||||
assetHandler := http.FileServer(rice.MustFindBox("assets").HTTPBox())
|
assetHandler := http.FileServer(rice.MustFindBox("assets").HTTPBox())
|
||||||
|
|
||||||
// register routes
|
// register routes
|
||||||
app := router.New()
|
app := router.New(tmplBox)
|
||||||
|
|
||||||
app.GET("/", handler.WireGuardClients())
|
app.GET("/", handler.WireGuardClients())
|
||||||
app.GET("/login", handler.LoginPage())
|
app.GET("/login", handler.LoginPage())
|
||||||
|
|
|
@ -33,38 +33,32 @@ func (t *TemplateRegistry) Render(w io.Writer, name string, data interface{}, c
|
||||||
}
|
}
|
||||||
|
|
||||||
// New function
|
// New function
|
||||||
func New() *echo.Echo {
|
func New(tmplBox *rice.Box) *echo.Echo {
|
||||||
e := echo.New()
|
e := echo.New()
|
||||||
e.Use(session.Middleware(sessions.NewCookieStore([]byte("secret"))))
|
e.Use(session.Middleware(sessions.NewCookieStore([]byte("secret"))))
|
||||||
|
|
||||||
// create go rice box for embedded template
|
|
||||||
templateBox, err := rice.FindBox("../templates")
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// read html template file to string
|
// read html template file to string
|
||||||
tmplBaseString, err := templateBox.String("base.html")
|
tmplBaseString, err := tmplBox.String("base.html")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
tmplLoginString, err := templateBox.String("login.html")
|
tmplLoginString, err := tmplBox.String("login.html")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
tmplClientsString, err := templateBox.String("clients.html")
|
tmplClientsString, err := tmplBox.String("clients.html")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
tmplServerString, err := templateBox.String("server.html")
|
tmplServerString, err := tmplBox.String("server.html")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
tmplGlobalSettingsString, err := templateBox.String("global_settings.html")
|
tmplGlobalSettingsString, err := tmplBox.String("global_settings.html")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue