go: delete pertinent ENVs after loading settings
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
leo 2023-05-12 22:43:36 +02:00
parent e8ac4e39ce
commit fc4460d5e1
Signed by: wanderer
SSH Key Fingerprint: SHA256:Dp8+iwKHSlrMEHzE3bJnPng70I7LEsa3IJXRH/U+idQ

@ -1,6 +1,8 @@
package settings package settings
import ( import (
"os"
"git.dotya.ml/mirre-mt/pcmt/config" "git.dotya.ml/mirre-mt/pcmt/config"
"git.dotya.ml/mirre-mt/pcmt/slogging" "git.dotya.ml/mirre-mt/pcmt/slogging"
"golang.org/x/exp/slog" "golang.org/x/exp/slog"
@ -22,6 +24,14 @@ type Settings struct {
dbIsSetUp bool dbIsSetUp bool
} }
// cleantgt is a list of ENV vars pertaining to pcmt.
var cleantgt = []string{
"PCMT_LIVE",
"PCMT_DEVEL",
"PCMT_CONNSTRING",
"PCMT_DBTYPE",
}
// New returns a new instance of the settings struct. // New returns a new instance of the settings struct.
func New() *Settings { func New() *Settings {
return &Settings{} return &Settings{}
@ -205,3 +215,15 @@ func (s *Settings) SetDbType(dbType string) {
func (s *Settings) SetDbIsSetUp(is bool) { func (s *Settings) SetDbIsSetUp(is bool) {
s.dbIsSetUp = is s.dbIsSetUp = is
} }
// EraseENVs attempts to clear environment vars pertaining to pcmt.
func (s *Settings) EraseENVs() error {
for _, v := range cleantgt {
err := os.Unsetenv(v)
if err != nil {
return err
}
}
return nil
}