mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2025-05-10 18:05:48 +02:00
feat: use env to predefine admin user #214
This commit is contained in:
parent
13c4eb04a3
commit
4c74bc8619
10 changed files with 89 additions and 28 deletions
|
@ -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
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
package settings
|
||||
|
||||
type PredefinedUser struct {
|
||||
User string `json:"user"`
|
||||
Password string `json:"password"`
|
||||
}
|
||||
|
||||
var PredefinedUserSettings = &PredefinedUser{}
|
Loading…
Add table
Add a link
Reference in a new issue