mirror of
https://github.com/ngoduykhanh/wireguard-ui.git
synced 2025-06-07 00:46:58 +03:00
chore: code adjustment (#512)
This commit is contained in:
parent
8cfe9a3d5b
commit
45849a2aee
9 changed files with 79 additions and 69 deletions
|
@ -37,14 +37,14 @@ func New(dbPath string) (*JsonDB, error) {
|
|||
}
|
||||
|
||||
func (o *JsonDB) Init() error {
|
||||
var clientPath string = path.Join(o.dbPath, "clients")
|
||||
var serverPath string = path.Join(o.dbPath, "server")
|
||||
var userPath string = path.Join(o.dbPath, "users")
|
||||
var wakeOnLanHostsPath string = path.Join(o.dbPath, "wake_on_lan_hosts")
|
||||
var serverInterfacePath string = path.Join(serverPath, "interfaces.json")
|
||||
var serverKeyPairPath string = path.Join(serverPath, "keypair.json")
|
||||
var globalSettingPath string = path.Join(serverPath, "global_settings.json")
|
||||
var hashesPath string = path.Join(serverPath, "hashes.json")
|
||||
var clientPath = path.Join(o.dbPath, "clients")
|
||||
var serverPath = path.Join(o.dbPath, "server")
|
||||
var userPath = path.Join(o.dbPath, "users")
|
||||
var wakeOnLanHostsPath = path.Join(o.dbPath, "wake_on_lan_hosts")
|
||||
var serverInterfacePath = path.Join(serverPath, "interfaces.json")
|
||||
var serverKeyPairPath = path.Join(serverPath, "keypair.json")
|
||||
var globalSettingPath = path.Join(serverPath, "global_settings.json")
|
||||
var hashesPath = path.Join(serverPath, "hashes.json")
|
||||
|
||||
// create directories if they do not exist
|
||||
if _, err := os.Stat(clientPath); os.IsNotExist(err) {
|
||||
|
@ -189,7 +189,7 @@ func (o *JsonDB) GetUsers() ([]model.User, error) {
|
|||
for _, i := range results {
|
||||
user := model.User{}
|
||||
|
||||
if err := json.Unmarshal([]byte(i), &user); err != nil {
|
||||
if err := json.Unmarshal(i, &user); err != nil {
|
||||
return users, fmt.Errorf("cannot decode user json structure: %v", err)
|
||||
}
|
||||
users = append(users, user)
|
||||
|
@ -267,7 +267,7 @@ func (o *JsonDB) GetClients(hasQRCode bool) ([]model.ClientData, error) {
|
|||
clientData := model.ClientData{}
|
||||
|
||||
// get client info
|
||||
if err := json.Unmarshal([]byte(f), &client); err != nil {
|
||||
if err := json.Unmarshal(f, &client); err != nil {
|
||||
return clients, fmt.Errorf("cannot decode client json structure: %v", err)
|
||||
}
|
||||
|
||||
|
@ -278,7 +278,7 @@ func (o *JsonDB) GetClients(hasQRCode bool) ([]model.ClientData, error) {
|
|||
|
||||
png, err := qrcode.Encode(util.BuildClientConfig(client, server, globalSettings), qrcode.Medium, 256)
|
||||
if err == nil {
|
||||
clientData.QRCode = "data:image/png;base64," + base64.StdEncoding.EncodeToString([]byte(png))
|
||||
clientData.QRCode = "data:image/png;base64," + base64.StdEncoding.EncodeToString(png)
|
||||
} else {
|
||||
fmt.Print("Cannot generate QR code: ", err)
|
||||
}
|
||||
|
@ -315,7 +315,7 @@ func (o *JsonDB) GetClientByID(clientID string, qrCodeSettings model.QRCodeSetti
|
|||
|
||||
png, err := qrcode.Encode(util.BuildClientConfig(client, server, globalSettings), qrcode.Medium, 256)
|
||||
if err == nil {
|
||||
clientData.QRCode = "data:image/png;base64," + base64.StdEncoding.EncodeToString([]byte(png))
|
||||
clientData.QRCode = "data:image/png;base64," + base64.StdEncoding.EncodeToString(png)
|
||||
} else {
|
||||
fmt.Print("Cannot generate QR code: ", err)
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ func (o *JsonDB) GetWakeOnLanHosts() ([]model.WakeOnLanHost, error) {
|
|||
host := model.WakeOnLanHost{}
|
||||
|
||||
// get client info
|
||||
if err := json.Unmarshal([]byte(f), &host); err != nil {
|
||||
if err := json.Unmarshal(f, &host); err != nil {
|
||||
return hosts, fmt.Errorf("cannot decode client json structure: %v", err)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue