@@ -553,6 +553,21 @@ func (config *Config) SectionsByPrefix(prefix string) map[string]*ConfigSection
553553 return list
554554}
555555
556+ func (config * Config ) getCombine (section , key string ) (combine , trim string ) {
557+ switch section {
558+ case "/settings/check/logfile" :
559+ if key == "allowed pattern" {
560+ return " , " , ", "
561+ }
562+ default :
563+ if key == "allowed hosts" {
564+ return " , " , ", "
565+ }
566+ }
567+
568+ return "" , ""
569+ }
570+
556571// parseString parses string from config section.
557572func configParseString (val string ) (string , error ) {
558573 val = strings .TrimSpace (val )
@@ -661,7 +676,9 @@ func (config *Config) ReplaceMacrosDefault(section *ConfigSection, timezone *tim
661676 section .data [key ] = val
662677
663678 raw := section .raw [key ]
664- raw = ReplaceMacros (raw , timezone , defaultMacros )
679+ for i , r := range raw {
680+ raw [i ] = ReplaceMacros (r , timezone , defaultMacros )
681+ }
665682 section .raw [key ] = raw
666683 }
667684}
@@ -729,7 +746,7 @@ type ConfigSection struct {
729746 cfg * Config // reference to parent config collection
730747 name string // section name
731748 data ConfigData // actual config data
732- raw ConfigData // raw config data (including quotes and such)
749+ raw map [ string ][] string // raw config data (including quotes and such)
733750 keys []string // keys from config data
734751 comments map [string ][]string // comments sorted by config keys
735752}
@@ -740,7 +757,7 @@ func NewConfigSection(cfg *Config, name string) *ConfigSection {
740757 cfg : cfg ,
741758 name : name ,
742759 data : make (map [string ]string , 0 ),
743- raw : make (map [string ]string , 0 ),
760+ raw : make (map [string ][] string , 0 ),
744761 keys : make ([]string , 0 ),
745762 comments : make (map [string ][]string , 0 ),
746763 }
@@ -758,13 +775,21 @@ func (cs *ConfigSection) String() string {
758775 data = append (data , cs .comments [key ]... )
759776 val := cs .data [key ]
760777 raw := cs .raw [key ]
761- if raw != "" {
762- val = raw
763- }
764- if val == "" {
765- data = append (data , fmt .Sprintf ("%s =" , key ))
766- } else {
767- data = append (data , fmt .Sprintf ("%s = %s" , key , cs .data [key ]))
778+ switch len (raw ) {
779+ case 0 , 1 :
780+ if val == "" {
781+ data = append (data , fmt .Sprintf ("%s =" , key ))
782+ } else {
783+ data = append (data , fmt .Sprintf ("%s = %s" , key , cs .data [key ]))
784+ }
785+ default :
786+ for i , line := range raw {
787+ if i == 0 {
788+ data = append (data , fmt .Sprintf ("%s = %s" , key , line ))
789+ } else {
790+ data = append (data , fmt .Sprintf ("%s += %s" , key , line ))
791+ }
792+ }
768793 }
769794 }
770795
@@ -778,6 +803,7 @@ func (cs *ConfigSection) String() string {
778803// be stored as is, including quotes.
779804func (cs * ConfigSection ) SetRaw (key , value string ) error {
780805 rawValue := value
806+ newRawValue := []string {rawValue }
781807
782808 useAppend := false
783809 if strings .HasSuffix (key , "+" ) {
@@ -793,8 +819,13 @@ func (cs *ConfigSection) SetRaw(key, value string) error {
793819 if useAppend {
794820 curRaw , cur , ok := cs .GetStringRaw (key )
795821 if ok {
796- value = cur + value
797- rawValue = curRaw + rawValue
822+ newRawValue = append (curRaw , rawValue )
823+ combine , trim := cs .cfg .getCombine (cs .name , key )
824+ if combine == "" {
825+ value = cur + value
826+ } else {
827+ value = strings .TrimRight (cur , trim ) + combine + strings .TrimLeft (value , trim )
828+ }
798829 }
799830 }
800831
@@ -803,7 +834,7 @@ func (cs *ConfigSection) SetRaw(key, value string) error {
803834 }
804835
805836 cs .data [key ] = value
806- cs .raw [key ] = rawValue
837+ cs .raw [key ] = newRawValue
807838
808839 return nil
809840}
@@ -815,10 +846,10 @@ func (cs *ConfigSection) Set(key, value string) {
815846 }
816847
817848 cs .data [key ] = value
818- cs .raw [key ] = ""
849+ cs .raw [key ] = [] string { value }
819850}
820851
821- // Insert is just like Set but trys to find the key in comments first and will uncomment that one
852+ // Insert is just like Set but tries to find the key in comments first and will uncomment that one
822853func (cs * ConfigSection ) Insert (key , value string ) {
823854 if cs .HasKey (key ) {
824855 cs .data [key ] = value
@@ -939,11 +970,11 @@ func (cs *ConfigSection) GetString(key string) (val string, ok bool) {
939970// GetStringRaw returns the raw string (including quotes)
940971// along the clean string from config section.
941972// it returns the value if found and sets ok to true.
942- func (cs * ConfigSection ) GetStringRaw (key string ) (raw , val string , ok bool ) {
973+ func (cs * ConfigSection ) GetStringRaw (key string ) (raw [] string , val string , ok bool ) {
943974 raw = cs .raw [key ]
944975 val , ok = cs .data [key ]
945- if raw == "" {
946- raw = val
976+ if len ( raw ) == 0 {
977+ raw = [] string { val }
947978 }
948979 if ok && cs .isUsable (key , val ) {
949980 macros := make ([]map [string ]string , 0 )
0 commit comments