errors linting
This commit is contained in:
@@ -21,20 +21,18 @@ func GET(w http.ResponseWriter, r *http.Request, c *config.Config, filename stri
|
||||
// Check if the file format is supported. If not, send a "Not Acceptable"
|
||||
// header and an error
|
||||
if !utils.CanBeEdited(filename) {
|
||||
return 406, errors.New("File format not supported.")
|
||||
return http.StatusNotAcceptable, errors.New("File format not supported.")
|
||||
}
|
||||
|
||||
// Check if the file exists. If it doesn't, send a "Not Found" message
|
||||
if _, err := os.Stat(filename); os.IsNotExist(err) {
|
||||
w.Write([]byte(err.Error()))
|
||||
return 404, nil
|
||||
return http.StatusNotFound, nil
|
||||
}
|
||||
|
||||
// Open the file and check if there was some error while opening
|
||||
file, err := ioutil.ReadFile(filename)
|
||||
if err != nil {
|
||||
w.Write([]byte(err.Error()))
|
||||
return 500, err
|
||||
return http.StatusInternalServerError, err
|
||||
}
|
||||
|
||||
// Create a new editor variable and set the extension
|
||||
@@ -55,8 +53,7 @@ func GET(w http.ResponseWriter, r *http.Request, c *config.Config, filename stri
|
||||
buffer := bytes.NewBuffer(file)
|
||||
file, err := parser.ReadFrom(buffer)
|
||||
if err != nil {
|
||||
w.Write([]byte(err.Error()))
|
||||
return 500, err
|
||||
return http.StatusInternalServerError, err
|
||||
}
|
||||
|
||||
if strings.Contains(string(file.FrontMatter()), "date") {
|
||||
@@ -86,8 +83,7 @@ func GET(w http.ResponseWriter, r *http.Request, c *config.Config, filename stri
|
||||
|
||||
// Check if there were any errors
|
||||
if err != nil {
|
||||
w.Write([]byte(err.Error()))
|
||||
return 500, err
|
||||
return http.StatusInternalServerError, err
|
||||
}
|
||||
default:
|
||||
// The editor will handle only content
|
||||
@@ -105,11 +101,10 @@ func GET(w http.ResponseWriter, r *http.Request, c *config.Config, filename stri
|
||||
tpl, err := utils.GetTemplate(r, functions, "editor", "frontmatter")
|
||||
|
||||
if err != nil {
|
||||
w.Write([]byte(err.Error()))
|
||||
return 500, err
|
||||
return http.StatusInternalServerError, err
|
||||
}
|
||||
|
||||
return 200, tpl.Execute(w, page)
|
||||
return http.StatusOK, tpl.Execute(w, page)
|
||||
}
|
||||
|
||||
func hasFrontMatterRune(file []byte) bool {
|
||||
|
||||
@@ -52,7 +52,7 @@ func POST(w http.ResponseWriter, r *http.Request, c *config.Config, filename str
|
||||
|
||||
file = f
|
||||
default:
|
||||
return 400, nil
|
||||
return http.StatusNotFound, nil
|
||||
}
|
||||
|
||||
// Write the file
|
||||
@@ -60,12 +60,12 @@ func POST(w http.ResponseWriter, r *http.Request, c *config.Config, filename str
|
||||
|
||||
if err != nil {
|
||||
w.Write([]byte(err.Error()))
|
||||
return 500, err
|
||||
return http.StatusInternalServerError, err
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.Write([]byte("{}"))
|
||||
return 200, nil
|
||||
return http.StatusOK, nil
|
||||
}
|
||||
|
||||
func parseFrontMatterOnlyFile(rawFile map[string]interface{}, filename string) ([]byte, int, error) {
|
||||
@@ -80,7 +80,7 @@ func parseFrontMatterOnlyFile(rawFile map[string]interface{}, filename string) (
|
||||
case "yaml":
|
||||
mark = rune('-')
|
||||
default:
|
||||
return []byte{}, 400, nil
|
||||
return []byte{}, http.StatusNotFound, nil
|
||||
}
|
||||
|
||||
f, err := parser.InterfaceToFrontMatter(rawFile, mark)
|
||||
@@ -100,10 +100,10 @@ func parseFrontMatterOnlyFile(rawFile map[string]interface{}, filename string) (
|
||||
f = []byte(fString)
|
||||
|
||||
if err != nil {
|
||||
return []byte{}, 500, err
|
||||
return []byte{}, http.StatusInternalServerError, err
|
||||
}
|
||||
|
||||
return f, 200, nil
|
||||
return f, http.StatusOK, nil
|
||||
}
|
||||
|
||||
func parseCompleteFile(r *http.Request, c *config.Config, rawFile map[string]interface{}, filename string) ([]byte, int, error) {
|
||||
@@ -116,10 +116,10 @@ func parseCompleteFile(r *http.Request, c *config.Config, rawFile map[string]int
|
||||
|
||||
// Schedule the post
|
||||
if r.Header.Get("X-Schedule") == "true" {
|
||||
t, err := time.Parse("2006-01-02 15:04:05-07:00", rawFile["date"].(string))
|
||||
t, err := time.Parse("http.StatusOK6-01-02 15:04:05-07:00", rawFile["date"].(string))
|
||||
|
||||
if err != nil {
|
||||
return []byte{}, 500, err
|
||||
return []byte{}, http.StatusInternalServerError, err
|
||||
}
|
||||
|
||||
scheduler := cron.New()
|
||||
@@ -160,7 +160,7 @@ func parseCompleteFile(r *http.Request, c *config.Config, rawFile map[string]int
|
||||
jsonFrontmatter, err := json.Marshal(rawFile)
|
||||
|
||||
if err != nil {
|
||||
return []byte{}, 500, err
|
||||
return []byte{}, http.StatusInternalServerError, err
|
||||
}
|
||||
|
||||
// Indents the json
|
||||
@@ -171,5 +171,5 @@ func parseCompleteFile(r *http.Request, c *config.Config, rawFile map[string]int
|
||||
f := new(bytes.Buffer)
|
||||
f.Write(frontMatterBuffer.Bytes())
|
||||
f.Write([]byte(mainContent))
|
||||
return f.Bytes(), 200, nil
|
||||
return f.Bytes(), http.StatusOK, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user