From fc4460d5e10d819111ca81e7d1ee85b82359120d Mon Sep 17 00:00:00 2001 From: leo Date: Fri, 12 May 2023 22:43:36 +0200 Subject: [PATCH] go: delete pertinent ENVs after loading settings --- app/settings/settings.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/app/settings/settings.go b/app/settings/settings.go index 7af9fc8..cb15ce1 100644 --- a/app/settings/settings.go +++ b/app/settings/settings.go @@ -1,6 +1,8 @@ package settings import ( + "os" + "git.dotya.ml/mirre-mt/pcmt/config" "git.dotya.ml/mirre-mt/pcmt/slogging" "golang.org/x/exp/slog" @@ -22,6 +24,14 @@ type Settings struct { 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. func New() *Settings { return &Settings{} @@ -205,3 +215,15 @@ func (s *Settings) SetDbType(dbType string) { func (s *Settings) SetDbIsSetUp(is bool) { 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 +}