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:
Khanh Ngo 2020-05-21 15:51:24 +07:00 committed by GitHub
parent b741a915ae
commit 9a27cc366f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 169 additions and 34 deletions

View file

@ -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