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
No related branches found
No related tags found
1 merge request!249config: enable UDP for openvpn by default
Pipeline #244838 failed
......@@ -17,6 +17,8 @@ package config
import (
"encoding/json"
"errors"
"io/fs"
"os"
"path"
"time"
......@@ -61,8 +63,10 @@ func ParseConfig() *Config {
var conf Config
f, err := os.Open(configPath)
if err != nil {
conf.save()
if err != nil && errors.Is(err, fs.ErrNotExist) {
log.Debug().
Msg("Config file doesn't exist. Using default values to create")
conf.setDefaults()
} else {
defer f.Close()
dec := json.NewDecoder(f)
......@@ -84,6 +88,13 @@ func ParseConfig() *Config {
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 {
c.file.UserStoppedVPN = vpnStopped
return c.save()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment