mirror of
https://github.com/lordmathis/lemma.git
synced 2025-11-06 16:04:23 +00:00
Initial git sorage backend implementation
This commit is contained in:
@@ -7,8 +7,14 @@ import (
|
||||
)
|
||||
|
||||
type UserSettings struct {
|
||||
Theme string `json:"theme" validate:"oneof=light dark"`
|
||||
AutoSave bool `json:"autoSave"`
|
||||
Theme string `json:"theme" validate:"oneof=light dark"`
|
||||
AutoSave bool `json:"autoSave"`
|
||||
GitEnabled bool `json:"git_enabled"`
|
||||
GitURL string `json:"git_url" validate:"required_with=GitEnabled"`
|
||||
GitUser string `json:"git_user" validate:"required_with=GitEnabled"`
|
||||
GitToken string `json:"git_token" validate:"required_with=GitEnabled"`
|
||||
GitAutoCommit bool `json:"git_auto_commit"`
|
||||
GitCommitMsgTemplate string `json:"git_commit_msg_template"`
|
||||
}
|
||||
|
||||
type Settings struct {
|
||||
@@ -16,15 +22,25 @@ type Settings struct {
|
||||
Settings UserSettings `json:"settings" validate:"required"`
|
||||
}
|
||||
|
||||
var defaultUserSettings = UserSettings{
|
||||
Theme: "light",
|
||||
AutoSave: false,
|
||||
GitEnabled: false,
|
||||
GitCommitMsgTemplate: "Update ${filename}",
|
||||
}
|
||||
|
||||
var validate = validator.New()
|
||||
|
||||
func (s *Settings) Validate() error {
|
||||
return validate.Struct(s)
|
||||
}
|
||||
|
||||
func (s *Settings) SetDefaults(defaults UserSettings) {
|
||||
func (s *Settings) SetDefaults() {
|
||||
if s.Settings.Theme == "" {
|
||||
s.Settings.Theme = defaults.Theme
|
||||
s.Settings.Theme = defaultUserSettings.Theme
|
||||
}
|
||||
if s.Settings.GitCommitMsgTemplate == "" {
|
||||
s.Settings.GitCommitMsgTemplate = defaultUserSettings.GitCommitMsgTemplate
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user