Initial git sorage backend implementation

This commit is contained in:
2024-09-28 14:52:02 +02:00
parent 122860d230
commit 0558ea292b
8 changed files with 427 additions and 26 deletions

View File

@@ -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
}
}