errors linting
parent
24871ee151
commit
58dcc9feb0
|
@ -20,8 +20,7 @@ func GET(w http.ResponseWriter, r *http.Request, c *config.Config) (int, error)
|
||||||
tpl, err := utils.GetTemplate(r, functions, "browse")
|
tpl, err := utils.GetTemplate(r, functions, "browse")
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.Write([]byte(err.Error()))
|
return http.StatusInternalServerError, err
|
||||||
return 500, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
b := browse.Browse{
|
b := browse.Browse{
|
||||||
|
|
|
@ -34,11 +34,11 @@ func POST(w http.ResponseWriter, r *http.Request) (int, error) {
|
||||||
// Check if filename and archetype are specified in
|
// Check if filename and archetype are specified in
|
||||||
// the request
|
// the request
|
||||||
if _, ok := info["filename"]; !ok {
|
if _, ok := info["filename"]; !ok {
|
||||||
return 400, errors.New("Filename not specified.")
|
return http.StatusBadRequest, errors.New("Filename not specified.")
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, ok := info["archetype"]; !ok {
|
if _, ok := info["archetype"]; !ok {
|
||||||
return 400, errors.New("Archtype not specified.")
|
return http.StatusBadRequest, errors.New("Archtype not specified.")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sanitize the file name path
|
// Sanitize the file name path
|
||||||
|
@ -62,7 +62,7 @@ func POST(w http.ResponseWriter, r *http.Request) (int, error) {
|
||||||
err = utils.CopyFile(archetype+".markdown", filename)
|
err = utils.CopyFile(archetype+".markdown", filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.Write([]byte(err.Error()))
|
w.Write([]byte(err.Error()))
|
||||||
return 500, err
|
return http.StatusInternalServerError, err
|
||||||
}
|
}
|
||||||
|
|
||||||
w.Header().Set("Location", "/admin/edit/"+filename)
|
w.Header().Set("Location", "/admin/edit/"+filename)
|
||||||
|
@ -76,7 +76,7 @@ func POST(w http.ResponseWriter, r *http.Request) (int, error) {
|
||||||
err = utils.CopyFile(archetype+".md", filename)
|
err = utils.CopyFile(archetype+".md", filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.Write([]byte(err.Error()))
|
w.Write([]byte(err.Error()))
|
||||||
return 500, err
|
return http.StatusInternalServerError, err
|
||||||
}
|
}
|
||||||
|
|
||||||
w.Header().Set("Location", "/admin/edit/"+filename)
|
w.Header().Set("Location", "/admin/edit/"+filename)
|
||||||
|
@ -89,7 +89,7 @@ func POST(w http.ResponseWriter, r *http.Request) (int, error) {
|
||||||
wf, err := os.Create(filename)
|
wf, err := os.Create(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.Write([]byte(err.Error()))
|
w.Write([]byte(err.Error()))
|
||||||
return 500, err
|
return http.StatusInternalServerError, err
|
||||||
}
|
}
|
||||||
|
|
||||||
defer wf.Close()
|
defer wf.Close()
|
||||||
|
@ -97,7 +97,7 @@ func POST(w http.ResponseWriter, r *http.Request) (int, error) {
|
||||||
w.Header().Set("Location", "/admin/edit/"+filename)
|
w.Header().Set("Location", "/admin/edit/"+filename)
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
w.Write([]byte("{}"))
|
w.Write([]byte("{}"))
|
||||||
return 200, nil
|
return http.StatusOK, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func upload(w http.ResponseWriter, r *http.Request) (int, error) {
|
func upload(w http.ResponseWriter, r *http.Request) (int, error) {
|
||||||
|
@ -105,7 +105,7 @@ func upload(w http.ResponseWriter, r *http.Request) (int, error) {
|
||||||
err := r.ParseMultipartForm(100000)
|
err := r.ParseMultipartForm(100000)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.Write([]byte(err.Error()))
|
w.Write([]byte(err.Error()))
|
||||||
return 500, err
|
return http.StatusInternalServerError, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// For each file header in the multipart form
|
// For each file header in the multipart form
|
||||||
|
@ -116,25 +116,25 @@ func upload(w http.ResponseWriter, r *http.Request) (int, error) {
|
||||||
var infile multipart.File
|
var infile multipart.File
|
||||||
if infile, err = hdr.Open(); nil != err {
|
if infile, err = hdr.Open(); nil != err {
|
||||||
w.Write([]byte(err.Error()))
|
w.Write([]byte(err.Error()))
|
||||||
return 500, err
|
return http.StatusInternalServerError, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the file
|
// Create the file
|
||||||
var outfile *os.File
|
var outfile *os.File
|
||||||
if outfile, err = os.Create(r.URL.Path + hdr.Filename); nil != err {
|
if outfile, err = os.Create(r.URL.Path + hdr.Filename); nil != err {
|
||||||
w.Write([]byte(err.Error()))
|
w.Write([]byte(err.Error()))
|
||||||
return 500, err
|
return http.StatusInternalServerError, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy the file content
|
// Copy the file content
|
||||||
if _, err = io.Copy(outfile, infile); nil != err {
|
if _, err = io.Copy(outfile, infile); nil != err {
|
||||||
w.Write([]byte(err.Error()))
|
w.Write([]byte(err.Error()))
|
||||||
return 500, err
|
return http.StatusInternalServerError, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
w.Write([]byte("{}"))
|
w.Write([]byte("{}"))
|
||||||
return 200, nil
|
return http.StatusOK, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -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"
|
// Check if the file format is supported. If not, send a "Not Acceptable"
|
||||||
// header and an error
|
// header and an error
|
||||||
if !utils.CanBeEdited(filename) {
|
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
|
// Check if the file exists. If it doesn't, send a "Not Found" message
|
||||||
if _, err := os.Stat(filename); os.IsNotExist(err) {
|
if _, err := os.Stat(filename); os.IsNotExist(err) {
|
||||||
w.Write([]byte(err.Error()))
|
return http.StatusNotFound, nil
|
||||||
return 404, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open the file and check if there was some error while opening
|
// Open the file and check if there was some error while opening
|
||||||
file, err := ioutil.ReadFile(filename)
|
file, err := ioutil.ReadFile(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.Write([]byte(err.Error()))
|
return http.StatusInternalServerError, err
|
||||||
return 500, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a new editor variable and set the extension
|
// 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)
|
buffer := bytes.NewBuffer(file)
|
||||||
file, err := parser.ReadFrom(buffer)
|
file, err := parser.ReadFrom(buffer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.Write([]byte(err.Error()))
|
return http.StatusInternalServerError, err
|
||||||
return 500, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if strings.Contains(string(file.FrontMatter()), "date") {
|
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
|
// Check if there were any errors
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.Write([]byte(err.Error()))
|
return http.StatusInternalServerError, err
|
||||||
return 500, err
|
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
// The editor will handle only content
|
// 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")
|
tpl, err := utils.GetTemplate(r, functions, "editor", "frontmatter")
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.Write([]byte(err.Error()))
|
return http.StatusInternalServerError, err
|
||||||
return 500, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 200, tpl.Execute(w, page)
|
return http.StatusOK, tpl.Execute(w, page)
|
||||||
}
|
}
|
||||||
|
|
||||||
func hasFrontMatterRune(file []byte) bool {
|
func hasFrontMatterRune(file []byte) bool {
|
||||||
|
|
|
@ -52,7 +52,7 @@ func POST(w http.ResponseWriter, r *http.Request, c *config.Config, filename str
|
||||||
|
|
||||||
file = f
|
file = f
|
||||||
default:
|
default:
|
||||||
return 400, nil
|
return http.StatusNotFound, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write the file
|
// Write the file
|
||||||
|
@ -60,12 +60,12 @@ func POST(w http.ResponseWriter, r *http.Request, c *config.Config, filename str
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.Write([]byte(err.Error()))
|
w.Write([]byte(err.Error()))
|
||||||
return 500, err
|
return http.StatusInternalServerError, err
|
||||||
}
|
}
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
w.Write([]byte("{}"))
|
w.Write([]byte("{}"))
|
||||||
return 200, nil
|
return http.StatusOK, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseFrontMatterOnlyFile(rawFile map[string]interface{}, filename string) ([]byte, int, error) {
|
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":
|
case "yaml":
|
||||||
mark = rune('-')
|
mark = rune('-')
|
||||||
default:
|
default:
|
||||||
return []byte{}, 400, nil
|
return []byte{}, http.StatusNotFound, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
f, err := parser.InterfaceToFrontMatter(rawFile, mark)
|
f, err := parser.InterfaceToFrontMatter(rawFile, mark)
|
||||||
|
@ -100,10 +100,10 @@ func parseFrontMatterOnlyFile(rawFile map[string]interface{}, filename string) (
|
||||||
f = []byte(fString)
|
f = []byte(fString)
|
||||||
|
|
||||||
if err != nil {
|
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) {
|
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
|
// Schedule the post
|
||||||
if r.Header.Get("X-Schedule") == "true" {
|
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 {
|
if err != nil {
|
||||||
return []byte{}, 500, err
|
return []byte{}, http.StatusInternalServerError, err
|
||||||
}
|
}
|
||||||
|
|
||||||
scheduler := cron.New()
|
scheduler := cron.New()
|
||||||
|
@ -160,7 +160,7 @@ func parseCompleteFile(r *http.Request, c *config.Config, rawFile map[string]int
|
||||||
jsonFrontmatter, err := json.Marshal(rawFile)
|
jsonFrontmatter, err := json.Marshal(rawFile)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return []byte{}, 500, err
|
return []byte{}, http.StatusInternalServerError, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Indents the json
|
// Indents the json
|
||||||
|
@ -171,5 +171,5 @@ func parseCompleteFile(r *http.Request, c *config.Config, rawFile map[string]int
|
||||||
f := new(bytes.Buffer)
|
f := new(bytes.Buffer)
|
||||||
f.Write(frontMatterBuffer.Bytes())
|
f.Write(frontMatterBuffer.Bytes())
|
||||||
f.Write([]byte(mainContent))
|
f.Write([]byte(mainContent))
|
||||||
return f.Bytes(), 200, nil
|
return f.Bytes(), http.StatusOK, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue