Skip to content
This repository has been archived by the owner on Feb 28, 2023. It is now read-only.

Commit

Permalink
fix(frontend-conf): Use pointer with omitempty to ignore frontend con…
Browse files Browse the repository at this point in the history
…fig output

Signed-off-by: qwqcode <[email protected]>
  • Loading branch information
qwqcode committed May 4, 2022
1 parent 2cb8e40 commit a16977d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 27 deletions.
52 changes: 26 additions & 26 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,33 +262,33 @@ type NotifyLINEConf struct {

// 使用转换 @link https://transform.tools/json-to-go
type FrontendConf struct {
Placeholder string `mapstructure:"placeholder" json:"placeholder,omitempty"`
NoComment string `mapstructure:"noComment" json:"noComment,omitempty"`
SendBtn string `mapstructure:"sendBtn" json:"sendBtn,omitempty"`
DarkMode bool `mapstructure:"darkMode" json:"darkMode,omitempty"`
EditorTravel bool `mapstructure:"editorTravel" json:"editorTravel,omitempty"`
Emoticons string `mapstructure:"emoticons" json:"emoticons,omitempty"`
Vote bool `mapstructure:"vote" json:"vote,omitempty"`
VoteDown bool `mapstructure:"voteDown" json:"voteDown,omitempty"`
UaBadge bool `mapstructure:"uaBadge" json:"uaBadge,omitempty"`
ListSort bool `mapstructure:"listSort" json:"listSort,omitempty"`
PvEl string `mapstructure:"pvEl" json:"pvEl,omitempty"`
FlatMode string `mapstructure:"flatMode" json:"flatMode,omitempty"`
MaxNesting int `mapstructure:"maxNesting" json:"maxNesting,omitempty"`
Gravatar struct {
Default string `mapstructure:"default" json:"default,omitempty"`
Mirror string `mapstructure:"mirror" json:"mirror,omitempty"`
Placeholder *string `mapstructure:"placeholder" json:"placeholder,omitempty"`
NoComment *string `mapstructure:"noComment" json:"noComment,omitempty"`
SendBtn *string `mapstructure:"sendBtn" json:"sendBtn,omitempty"`
DarkMode *bool `mapstructure:"darkMode" json:"darkMode,omitempty"`
EditorTravel *bool `mapstructure:"editorTravel" json:"editorTravel,omitempty"`
Emoticons *string `mapstructure:"emoticons" json:"emoticons,omitempty"`
Vote *bool `mapstructure:"vote" json:"vote,omitempty"`
VoteDown *bool `mapstructure:"voteDown" json:"voteDown,omitempty"`
UaBadge *bool `mapstructure:"uaBadge" json:"uaBadge,omitempty"`
ListSort *bool `mapstructure:"listSort" json:"listSort,omitempty"`
PvEl *string `mapstructure:"pvEl" json:"pvEl,omitempty"`
FlatMode *string `mapstructure:"flatMode" json:"flatMode,omitempty"`
MaxNesting *int `mapstructure:"maxNesting" json:"maxNesting,omitempty"`
Gravatar *struct {
Default *string `mapstructure:"default" json:"default,omitempty"`
Mirror *string `mapstructure:"mirror" json:"mirror,omitempty"`
} `mapstructure:"gravatar" json:"gravatar,omitempty"`
Pagination struct {
PageSize int `mapstructure:"pageSize" json:"pageSize,omitempty"`
ReadMore bool `mapstructure:"readMore" json:"readMore,omitempty"`
AutoLoad bool `mapstructure:"autoLoad" json:"autoLoad,omitempty"`
Pagination *struct {
PageSize *int `mapstructure:"pageSize" json:"pageSize,omitempty"`
ReadMore *bool `mapstructure:"readMore" json:"readMore,omitempty"`
AutoLoad *bool `mapstructure:"autoLoad" json:"autoLoad,omitempty"`
} `mapstructure:"pagination" json:"pagination,omitempty"`
HeightLimit struct {
Content int `mapstructure:"content" json:"content,omitempty"`
Children int `mapstructure:"children" json:"children,omitempty"`
HeightLimit *struct {
Content *int `mapstructure:"content" json:"content,omitempty"`
Children *int `mapstructure:"children" json:"children,omitempty"`
} `mapstructure:"heightLimit" json:"heightLimit,omitempty"`
ImgUpload bool `mapstructure:"imgUpload" json:"imgUpload,omitempty"`
ReqTimeout int `mapstructure:"reqTimeout" json:"reqTimeout,omitempty"`
VersionCheck bool `mapstructure:"versionCheck" json:"versionCheck,omitempty"`
ImgUpload *bool `mapstructure:"imgUpload" json:"imgUpload,omitempty"`
ReqTimeout *int `mapstructure:"reqTimeout" json:"reqTimeout,omitempty"`
VersionCheck *bool `mapstructure:"versionCheck" json:"versionCheck,omitempty"`
}
2 changes: 1 addition & 1 deletion http/a_resp.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func GetApiPublicConfDataMap(c echo.Context) Map {
}

frontendConf := config.Instance.Frontend
frontendConf.ImgUpload = imgUpload
frontendConf.ImgUpload = &imgUpload

return Map{
"img_upload": imgUpload,
Expand Down

1 comment on commit a16977d

@qwqcode
Copy link
Member Author

@qwqcode qwqcode commented on a16977d May 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

关联:

https://pkg.go.dev/encoding/json#Marshal

The "omitempty" option specifies that the field should be omitted from the encoding if the field has an empty value, defined as false, 0, a nil pointer, a nil interface value, and any empty array, slice, map, or string.

https://stackoverflow.com/questions/18088294/how-to-not-marshal-an-empty-struct-into-json-with-go

ArtalkJS/Artalk#135

Please sign in to comment.