mirror of
https://github.com/ngoduykhanh/wireguard-ui.git
synced 2025-05-23 00:15:19 +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
15
util/util.go
15
util/util.go
|
@ -10,6 +10,7 @@ import (
|
|||
"text/template"
|
||||
"time"
|
||||
|
||||
rice "github.com/GeertJohan/go.rice"
|
||||
externalip "github.com/glendc/go-external-ip"
|
||||
"github.com/ngoduykhanh/wireguard-ui/model"
|
||||
"github.com/sdomino/scribble"
|
||||
|
@ -268,7 +269,7 @@ func GetAvailableIP(cidr string, allocatedList []string) (string, error) {
|
|||
}
|
||||
}
|
||||
|
||||
return "", errors.New("No more available ip address")
|
||||
return "", errors.New("no more available ip address")
|
||||
}
|
||||
|
||||
// ValidateIPAllocation to validate the list of client's ip allocation
|
||||
|
@ -312,12 +313,20 @@ func ValidateIPAllocation(serverAddresses []string, ipAllocatedList []string, ip
|
|||
}
|
||||
|
||||
// WriteWireGuardServerConfig to write Wireguard server config. e.g. wg0.conf
|
||||
func WriteWireGuardServerConfig(serverConfig model.Server, clientDataList []model.ClientData, globalSettings model.GlobalSetting) error {
|
||||
t, err := template.ParseFiles("templates/wg.conf")
|
||||
func WriteWireGuardServerConfig(tmplBox *rice.Box, serverConfig model.Server, clientDataList []model.ClientData, globalSettings model.GlobalSetting) error {
|
||||
// read wg.conf template file to string
|
||||
tmplWireguardConf, err := tmplBox.String("wg.conf")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// parse the template
|
||||
t, err := template.New("wg_config").Parse(tmplWireguardConf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// write config file to disk
|
||||
f, err := os.Create(globalSettings.ConfigFilePath)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue