Skip to content
Snippets Groups Projects
Commit 3b24fc3a authored by jkito's avatar jkito :skull: Committed by jkito
Browse files

config: enable UDP for openvpn by default

this adds a new helper setDefaults() in the config
package and calls it when the config file  doesn't
exist, this provides a way for us to have  default
values for the config options

setDefaults currently only sets the UDP config  to
'true' since it is expected that UDP is enabled by
default
parent e237419f
Branches
Tags
1 merge request!249config: enable UDP for openvpn by default
Pipeline #244838 failed
...@@ -17,6 +17,8 @@ package config ...@@ -17,6 +17,8 @@ package config
import ( import (
"encoding/json" "encoding/json"
"errors"
"io/fs"
"os" "os"
"path" "path"
"time" "time"
...@@ -61,8 +63,10 @@ func ParseConfig() *Config { ...@@ -61,8 +63,10 @@ func ParseConfig() *Config {
var conf Config var conf Config
f, err := os.Open(configPath) f, err := os.Open(configPath)
if err != nil { if err != nil && errors.Is(err, fs.ErrNotExist) {
conf.save() log.Debug().
Msg("Config file doesn't exist. Using default values to create")
conf.setDefaults()
} else { } else {
defer f.Close() defer f.Close()
dec := json.NewDecoder(f) dec := json.NewDecoder(f)
...@@ -84,6 +88,13 @@ func ParseConfig() *Config { ...@@ -84,6 +88,13 @@ func ParseConfig() *Config {
return &conf return &conf
} }
func (c *Config) setDefaults() {
if err := c.SetUseUDP(true); err != nil {
log.Err(err).
Msg("Unable to set default for UDP config")
}
}
func (c *Config) SetUserStoppedVPN(vpnStopped bool) error { func (c *Config) SetUserStoppedVPN(vpnStopped bool) error {
c.file.UserStoppedVPN = vpnStopped c.file.UserStoppedVPN = vpnStopped
return c.save() return c.save()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment