feat: use env to predefine admin user #214

This commit is contained in:
Jacky 2024-05-06 22:55:05 +08:00
parent 13c4eb04a3
commit 4c74bc8619
No known key found for this signature in database
GPG key ID: 215C21B10DF38B4D
10 changed files with 89 additions and 28 deletions

View file

@ -69,12 +69,6 @@ func MapTo() {
}
}
func ReflectFrom() {
for k, v := range sections {
reflectFrom(k, v)
}
}
func mapTo(section string, v interface{}) {
err := Conf.Section(section).MapTo(v)
if err != nil {
@ -90,6 +84,10 @@ func reflectFrom(section string, v interface{}) {
}
func Save() (err error) {
for k, v := range sections {
reflectFrom(k, v)
}
err = Conf.SaveTo(ConfPath)
if err != nil {
return

View file

@ -52,6 +52,7 @@ func TestSetup(t *testing.T) {
_ = os.Setenv("NGINX_UI_LOGROTATE_CMD", "logrotate /custom/logrotate.conf")
_ = os.Setenv("NGINX_UI_LOGROTATE_INTERVAL", "60")
ConfPath = "app.testing.ini"
Setup()
assert.Equal(t, "8080", ServerSettings.HttpPort)
@ -96,4 +97,5 @@ func TestSetup(t *testing.T) {
assert.Equal(t, 60, LogrotateSettings.Interval)
os.Clearenv()
_ = os.Remove("app.testing.ini")
}

View file

@ -1,8 +0,0 @@
package settings
type PredefinedUser struct {
User string `json:"user"`
Password string `json:"password"`
}
var PredefinedUserSettings = &PredefinedUser{}