Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions internal/leetcode/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,10 @@ func Clean() {
}

func fileGetContents(filename string) []byte {
data, err := ioutil.ReadFile(filename)
checkErr(err)
return data
if cts, err := ioutil.ReadFile(filename); err == nil {
return cts
}
return nil
}

func jsonEncode(v interface{}) []byte {
Expand All @@ -85,17 +86,19 @@ func jsonEncode(v interface{}) []byte {
}

func jsonDecode(data []byte, v interface{}) {
err := json.Unmarshal(data, v)
checkErr(err)
if len(data) > 0 {
err := json.Unmarshal(data, v)
checkErr(err)
}
}

func saveCookies(cookies []*http.Cookie) {
filePutContents(getCachePath(cookiesFile), jsonEncode(cookies))
}

func getCookies() (cookies []*http.Cookie) {
data := fileGetContents(getCachePath(cookiesFile))
jsonDecode(data, &cookies)
cts := fileGetContents(getCachePath(cookiesFile))
jsonDecode(cts, &cookies)
return
}

Expand All @@ -104,7 +107,7 @@ func saveCredential(data url.Values) {
}

func getCredential() (data url.Values) {
body := fileGetContents(getCachePath(credentialsFile))
jsonDecode(body, &data)
cts := fileGetContents(getCachePath(credentialsFile))
jsonDecode(cts, &data)
return
}
4 changes: 2 additions & 2 deletions internal/leetcode/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
)

func GetTags() (tags []tagType) {
data := fileGetContents("tag/tags.json")
jsonDecode(data, &tags)
cts := fileGetContents("tag/tags.json")
jsonDecode(cts, &tags)
tags = tagsUnique(tags)
return
}
Expand Down