Simplified GetUser and GetPassword using libparams
This commit is contained in:
@@ -1,8 +1,6 @@
|
|||||||
package params
|
package params
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
|
|
||||||
libparams "github.com/qdm12/golibs/params"
|
libparams "github.com/qdm12/golibs/params"
|
||||||
"github.com/qdm12/private-internet-access-docker/internal/models"
|
"github.com/qdm12/private-internet-access-docker/internal/models"
|
||||||
)
|
)
|
||||||
@@ -15,13 +13,7 @@ func (p *paramsReader) GetUser() (s string, err error) {
|
|||||||
err = unsetenvErr
|
err = unsetenvErr
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
s, err = p.envParams.GetEnv("USER", libparams.CaseSensitiveValue())
|
return p.envParams.GetEnv("USER", libparams.CaseSensitiveValue(), libparams.Compulsory())
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
} else if len(s) == 0 {
|
|
||||||
return s, fmt.Errorf("USER environment variable cannot be empty")
|
|
||||||
}
|
|
||||||
return s, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetPassword obtains the password to use to connect to the VPN servers
|
// GetPassword obtains the password to use to connect to the VPN servers
|
||||||
@@ -32,13 +24,7 @@ func (p *paramsReader) GetPassword() (s string, err error) {
|
|||||||
err = unsetenvErr
|
err = unsetenvErr
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
s, err = p.envParams.GetEnv("PASSWORD", libparams.CaseSensitiveValue())
|
return p.envParams.GetEnv("PASSWORD", libparams.CaseSensitiveValue(), libparams.Compulsory())
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
} else if len(s) == 0 {
|
|
||||||
return s, fmt.Errorf("PASSWORD environment variable cannot be empty")
|
|
||||||
}
|
|
||||||
return s, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetNetworkProtocol obtains the network protocol to use to connect to the
|
// GetNetworkProtocol obtains the network protocol to use to connect to the
|
||||||
|
|||||||
Reference in New Issue
Block a user