This commit is contained in:
Liang Ding 2022-10-12 09:15:06 +08:00
parent 5aa5764974
commit 3c4af0fc85
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
2 changed files with 13 additions and 3 deletions

View file

@ -42,7 +42,13 @@ func getSnippet(c *gin.Context) {
enabled = false enabled = false
} }
confSnippets := model.LoadSnippets() confSnippets, err := model.LoadSnippets()
if nil != err {
ret.Code = -1
ret.Msg = "load snippets failed: " + err.Error()
return
}
var snippets []*conf.Snippet var snippets []*conf.Snippet
for _, s := range confSnippets { for _, s := range confSnippets {
if ("all" == typ || s.Type == typ) && (2 == enabledArg || s.Enabled == enabled) { if ("all" == typ || s.Type == typ) && (2 == enabledArg || s.Enabled == enabled) {

View file

@ -660,9 +660,13 @@ func clearWorkspaceTemp() {
logging.LogInfof("cleared workspace temp") logging.LogInfof("cleared workspace temp")
} }
func LoadSnippets() (ret []*conf.Snippet) { var loadSnippetsLock = sync.Mutex{}
ret = []*conf.Snippet{}
func LoadSnippets() (ret []*conf.Snippet, err error) {
loadSnippetsLock.Lock()
defer loadSnippetsLock.Unlock()
ret = []*conf.Snippet{}
confPath := filepath.Join(util.DataDir, "snippets/conf.json") confPath := filepath.Join(util.DataDir, "snippets/conf.json")
if !gulu.File.IsExist(confPath) { if !gulu.File.IsExist(confPath) {
return return