mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2025-05-11 02:15:48 +02:00
feat: customize local environment name #313
This commit is contained in:
parent
4c74bc8619
commit
1e9de6f21b
13 changed files with 78 additions and 36 deletions
|
@ -20,7 +20,8 @@ type Server struct {
|
|||
GithubProxy string `json:"github_proxy" binding:"omitempty,url"`
|
||||
CertRenewalInterval int `json:"cert_renewal_interval" binding:"min=7,max=21"`
|
||||
RecursiveNameservers []string `json:"recursive_nameservers" binding:"omitempty,dive,hostname_port"`
|
||||
SkipInstallation bool `json:"skip_installation"`
|
||||
SkipInstallation bool `json:"skip_installation" protected:"true"`
|
||||
Name string `json:"name" binding:"omitempty,alpha_num_dash_dot"`
|
||||
}
|
||||
|
||||
func (s *Server) GetCADir() string {
|
||||
|
|
|
@ -6,7 +6,8 @@ import (
|
|||
"gopkg.in/ini.v1"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
"reflect"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
@ -69,19 +70,7 @@ func MapTo() {
|
|||
}
|
||||
}
|
||||
|
||||
func mapTo(section string, v interface{}) {
|
||||
err := Conf.Section(section).MapTo(v)
|
||||
if err != nil {
|
||||
log.Fatalf("Cfg.MapTo %s err: %v", section, err)
|
||||
}
|
||||
}
|
||||
|
||||
func reflectFrom(section string, v interface{}) {
|
||||
err := Conf.Section(section).ReflectFrom(v)
|
||||
if err != nil {
|
||||
log.Fatalf("Cfg.ReflectFrom %s err: %v", section, err)
|
||||
}
|
||||
}
|
||||
|
||||
func Save() (err error) {
|
||||
for k, v := range sections {
|
||||
|
@ -95,6 +84,33 @@ func Save() (err error) {
|
|||
return
|
||||
}
|
||||
|
||||
func ProtectedFill(targetSettings interface{}, newSettings interface{}) {
|
||||
s := reflect.TypeOf(targetSettings).Elem()
|
||||
vt := reflect.ValueOf(targetSettings).Elem()
|
||||
vn := reflect.ValueOf(newSettings).Elem()
|
||||
|
||||
// copy the values from new to target settings if it is not protected
|
||||
for i := 0; i < s.NumField(); i++ {
|
||||
if s.Field(i).Tag.Get("protected") != "true" {
|
||||
vt.Field(i).Set(vn.Field(i))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func mapTo(section string, v interface{}) {
|
||||
err := Conf.Section(section).MapTo(v)
|
||||
if err != nil {
|
||||
log.Fatalf("Cfg.MapTo %s err: %v", section, err)
|
||||
}
|
||||
}
|
||||
|
||||
func reflectFrom(section string, v interface{}) {
|
||||
err := Conf.Section(section).ReflectFrom(v)
|
||||
if err != nil {
|
||||
log.Fatalf("Cfg.ReflectFrom %s err: %v", section, err)
|
||||
}
|
||||
}
|
||||
|
||||
func parseEnv(ptr interface{}, prefix string) {
|
||||
err := env.ParseWithOptions(ptr, env.Options{
|
||||
Prefix: EnvPrefix + prefix,
|
||||
|
@ -105,3 +121,5 @@ func parseEnv(ptr interface{}, prefix string) {
|
|||
log.Fatalf("settings.parseEnv: %v\n", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@ func TestSetup(t *testing.T) {
|
|||
_ = os.Setenv("NGINX_UI_SERVER_CERT_RENEWAL_INTERVAL", "14")
|
||||
_ = os.Setenv("NGINX_UI_SERVER_RECURSIVE_NAMESERVERS", "8.8.8.8")
|
||||
_ = os.Setenv("NGINX_UI_SERVER_SKIP_INSTALLATION", "true")
|
||||
_ = os.Setenv("NGINX_UI_SERVER_NAME", "test")
|
||||
|
||||
_ = os.Setenv("NGINX_UI_NGINX_ACCESS_LOG_PATH", "/tmp/nginx/access.log")
|
||||
_ = os.Setenv("NGINX_UI_NGINX_ERROR_LOG_PATH", "/tmp/nginx/error.log")
|
||||
|
@ -70,6 +71,7 @@ func TestSetup(t *testing.T) {
|
|||
assert.Equal(t, 14, ServerSettings.CertRenewalInterval)
|
||||
assert.Equal(t, []string{"8.8.8.8"}, ServerSettings.RecursiveNameservers)
|
||||
assert.Equal(t, true, ServerSettings.SkipInstallation)
|
||||
assert.Equal(t, "test", ServerSettings.Name)
|
||||
|
||||
assert.Equal(t, "/tmp/nginx/access.log", NginxSettings.AccessLogPath)
|
||||
assert.Equal(t, "/tmp/nginx/error.log", NginxSettings.ErrorLogPath)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue