From cd590f7a054a67958d287c1ead7cd9cea0a2a44a Mon Sep 17 00:00:00 2001 From: Paul Wilde Date: Wed, 18 Aug 2021 15:40:28 +0100 Subject: [PATCH] used json's omitempty on structs to tidy output --- src/global/global.go | 6 +++- src/global/structs/structs.go | 50 +++++++++++++++++----------------- src/web/responses/responses.go | 2 +- 3 files changed, 31 insertions(+), 27 deletions(-) diff --git a/src/global/global.go b/src/global/global.go index e88eac2..c79b9c5 100644 --- a/src/global/global.go +++ b/src/global/global.go @@ -108,7 +108,11 @@ func removeDisabledItems(cfg *Config) { 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 { data, err := json.Marshal(content) logger.CheckError(err) diff --git a/src/global/structs/structs.go b/src/global/structs/structs.go index 61186d8..a435bf0 100644 --- a/src/global/structs/structs.go +++ b/src/global/structs/structs.go @@ -18,41 +18,41 @@ type Config struct { BaseURL string `yaml:"BaseURL"` Domains []string `yaml:"Domains"` LocalDomain string `yaml:"LocalDomain"` - InMail Service `yaml:"InMail"` - OutMail Service `yaml:"OutMail"` - Calendar Service `yaml:"Calendar"` - AddressBook Service `yaml:"AddressBook"` - WebMail Service `yaml:"WebMail"` - OtherServices []Service `yaml:"OtherServices"` + InMail Service `yaml:"InMail" json:",omitempty"` + OutMail Service `yaml:"OutMail" json:",omitempty"` + Calendar Service `yaml:"Calendar" json:",omitempty"` + AddressBook Service `yaml:"AddressBook" json:",omitempty"` + WebMail Service `yaml:"WebMail" json:",omitempty"` + OtherServices []Service `yaml:"OtherServices" json:",omitempty"` } type Service struct { - Name string `yaml:"Name"` - Enabled bool `yaml:"Enabled"` - Type string `yaml:"Type"` - Server string `yaml:"Server"` - Port int `yaml:"Port"` - SocketType string `yaml:"SocketType"` - SPA bool `yaml:"SPA"` - UsernameIsFQDN bool `yaml:"UsernameIsFQDN"` - RequireLocalDomain bool `yaml:"RequireLocalDomain"` - NoAuthRequired bool `yaml:"NoAuthRequired"` - Authentication string `yaml:"Authentication"` + Name string `yaml:"Name" json:",omitempty"` + Enabled bool `yaml:"Enabled" json:",omitempty"` + Type string `yaml:"Type" json:",omitempty"` + Server string `yaml:"Server" json:",omitempty"` + Port int `yaml:"Port" json:",omitempty"` + SocketType string `yaml:"SocketType" json:",omitempty"` + SPA bool `yaml:"SPA" json:",omitempty"` + UsernameIsFQDN bool `yaml:"UsernameIsFQDN" json:",omitempty"` + RequireLocalDomain bool `yaml:"RequireLocalDomain" json:",omitempty"` + NoAuthRequired bool `yaml:"NoAuthRequired" json:",omitempty"` + Authentication string `yaml:"Authentication" json:",omitempty"` // For Outgoing Mail - POPAuth bool `yaml:"POPAuth"` - SMTPLast bool `yaml:"SMTPLast"` + POPAuth bool `yaml:"POPAuth" json:",omitempty"` + SMTPLast bool `yaml:"SMTPLast" json:",omitempty"` // For WebMail (Unused) - UsernameDivID string `yaml:"UsernameDivID"` - UsernameDivName string `yaml:"UsernameDivName"` - PasswordDivName string `yaml:"PasswordDivName"` - SubmitButtonID string `yaml:"SubmitButtonID"` - SubmitButtonName string `yaml:"SubmitButtonName"` + UsernameDivID string `yaml:"UsernameDivID" json:",omitempty"` + UsernameDivName string `yaml:"UsernameDivName" json:",omitempty"` + PasswordDivName string `yaml:"PasswordDivName" json:",omitempty"` + SubmitButtonID string `yaml:"SubmitButtonID" json:",omitempty"` + SubmitButtonName string `yaml:"SubmitButtonName" json:",omitempty"` } type Response struct { Url string `json:"url"` ContentType string `json:"content_type"` Message string `json:"message"` - Content map[string]interface{} `json:"content"` + Content map[string]interface{} `json:"content,omitempty"` Config Config `json:"_"` Email string `json:"_"` } diff --git a/src/web/responses/responses.go b/src/web/responses/responses.go index 6e7b799..cb61152 100644 --- a/src/web/responses/responses.go +++ b/src/web/responses/responses.go @@ -110,6 +110,6 @@ func DefaultResponse() string { } func OurConfig() string { global.ThisSession.ContentType = "application/json" - content := global.JSONify(global.MainConfig) + content := global.JSONifyConfig(global.MainConfig) return content }