used json's omitempty on structs to tidy output

This commit is contained in:
Paul Wilde 2021-08-18 15:40:28 +01:00
parent 3bdc960285
commit cd590f7a05
3 changed files with 31 additions and 27 deletions

View file

@ -108,7 +108,11 @@ func removeDisabledItems(cfg *Config) {
cfg.OtherServices = new_svcs cfg.OtherServices = new_svcs
} }
func JSONifyConfig(content Config) string {
data, err := json.Marshal(content)
logger.CheckError(err)
return string(data)
}
func JSONify(content interface{}) string { func JSONify(content interface{}) string {
data, err := json.Marshal(content) data, err := json.Marshal(content)
logger.CheckError(err) logger.CheckError(err)

View file

@ -18,41 +18,41 @@ type Config struct {
BaseURL string `yaml:"BaseURL"` BaseURL string `yaml:"BaseURL"`
Domains []string `yaml:"Domains"` Domains []string `yaml:"Domains"`
LocalDomain string `yaml:"LocalDomain"` LocalDomain string `yaml:"LocalDomain"`
InMail Service `yaml:"InMail"` InMail Service `yaml:"InMail" json:",omitempty"`
OutMail Service `yaml:"OutMail"` OutMail Service `yaml:"OutMail" json:",omitempty"`
Calendar Service `yaml:"Calendar"` Calendar Service `yaml:"Calendar" json:",omitempty"`
AddressBook Service `yaml:"AddressBook"` AddressBook Service `yaml:"AddressBook" json:",omitempty"`
WebMail Service `yaml:"WebMail"` WebMail Service `yaml:"WebMail" json:",omitempty"`
OtherServices []Service `yaml:"OtherServices"` OtherServices []Service `yaml:"OtherServices" json:",omitempty"`
} }
type Service struct { type Service struct {
Name string `yaml:"Name"` Name string `yaml:"Name" json:",omitempty"`
Enabled bool `yaml:"Enabled"` Enabled bool `yaml:"Enabled" json:",omitempty"`
Type string `yaml:"Type"` Type string `yaml:"Type" json:",omitempty"`
Server string `yaml:"Server"` Server string `yaml:"Server" json:",omitempty"`
Port int `yaml:"Port"` Port int `yaml:"Port" json:",omitempty"`
SocketType string `yaml:"SocketType"` SocketType string `yaml:"SocketType" json:",omitempty"`
SPA bool `yaml:"SPA"` SPA bool `yaml:"SPA" json:",omitempty"`
UsernameIsFQDN bool `yaml:"UsernameIsFQDN"` UsernameIsFQDN bool `yaml:"UsernameIsFQDN" json:",omitempty"`
RequireLocalDomain bool `yaml:"RequireLocalDomain"` RequireLocalDomain bool `yaml:"RequireLocalDomain" json:",omitempty"`
NoAuthRequired bool `yaml:"NoAuthRequired"` NoAuthRequired bool `yaml:"NoAuthRequired" json:",omitempty"`
Authentication string `yaml:"Authentication"` Authentication string `yaml:"Authentication" json:",omitempty"`
// For Outgoing Mail // For Outgoing Mail
POPAuth bool `yaml:"POPAuth"` POPAuth bool `yaml:"POPAuth" json:",omitempty"`
SMTPLast bool `yaml:"SMTPLast"` SMTPLast bool `yaml:"SMTPLast" json:",omitempty"`
// For WebMail (Unused) // For WebMail (Unused)
UsernameDivID string `yaml:"UsernameDivID"` UsernameDivID string `yaml:"UsernameDivID" json:",omitempty"`
UsernameDivName string `yaml:"UsernameDivName"` UsernameDivName string `yaml:"UsernameDivName" json:",omitempty"`
PasswordDivName string `yaml:"PasswordDivName"` PasswordDivName string `yaml:"PasswordDivName" json:",omitempty"`
SubmitButtonID string `yaml:"SubmitButtonID"` SubmitButtonID string `yaml:"SubmitButtonID" json:",omitempty"`
SubmitButtonName string `yaml:"SubmitButtonName"` SubmitButtonName string `yaml:"SubmitButtonName" json:",omitempty"`
} }
type Response struct { type Response struct {
Url string `json:"url"` Url string `json:"url"`
ContentType string `json:"content_type"` ContentType string `json:"content_type"`
Message string `json:"message"` Message string `json:"message"`
Content map[string]interface{} `json:"content"` Content map[string]interface{} `json:"content,omitempty"`
Config Config `json:"_"` Config Config `json:"_"`
Email string `json:"_"` Email string `json:"_"`
} }

View file

@ -110,6 +110,6 @@ func DefaultResponse() string {
} }
func OurConfig() string { func OurConfig() string {
global.ThisSession.ContentType = "application/json" global.ThisSession.ContentType = "application/json"
content := global.JSONify(global.MainConfig) content := global.JSONifyConfig(global.MainConfig)
return content return content
} }