mirror of
https://github.com/ngoduykhanh/wireguard-ui.git
synced 2025-07-09 17:34:25 +03:00
Single binary build (#10)
Single binary build Use go rice for embedding the static files and templates to the binary file
This commit is contained in:
parent
b741a915ae
commit
9a27cc366f
12 changed files with 169 additions and 34 deletions
18
main.go
18
main.go
|
@ -2,10 +2,12 @@ package main
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
rice "github.com/GeertJohan/go.rice"
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/ngoduykhanh/wireguard-ui/handler"
|
||||
"github.com/ngoduykhanh/wireguard-ui/router"
|
||||
"github.com/ngoduykhanh/wireguard-ui/util"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
@ -15,8 +17,14 @@ func main() {
|
|||
fmt.Print("Cannot init database: ", err)
|
||||
}
|
||||
|
||||
// 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())
|
||||
|
||||
// register routes
|
||||
app := router.New()
|
||||
app := router.New(tmplBox)
|
||||
|
||||
app.GET("/", handler.WireGuardClients())
|
||||
app.GET("/login", handler.LoginPage())
|
||||
|
@ -33,6 +41,10 @@ func main() {
|
|||
app.POST("/global-settings", handler.GlobalSettingSubmit())
|
||||
app.GET("/api/machine-ips", handler.MachineIPAddresses())
|
||||
app.GET("/api/suggest-client-ips", handler.SuggestIPAllocation())
|
||||
app.GET("/api/apply-wg-config", handler.ApplyServerConfig())
|
||||
app.GET("/api/apply-wg-config", handler.ApplyServerConfig(tmplBox))
|
||||
|
||||
// servers other static files
|
||||
app.GET("/static/*", echo.WrapHandler(http.StripPrefix("/static/", assetHandler)))
|
||||
|
||||
app.Logger.Fatal(app.Start("0.0.0.0:5000"))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue