Fixing errors from errcheck
This commit is contained in:
parent
4c7296e264
commit
7f27875bdb
30
handlers.go
30
handlers.go
|
@ -9,7 +9,10 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func healthcheck(w http.ResponseWriter, r *http.Request) {
|
func healthcheck(w http.ResponseWriter, r *http.Request) {
|
||||||
w.Write([]byte("ok"))
|
_, err := w.Write([]byte("ok"))
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("Error writing ok: %+v", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func reloadRules(c *Config) http.HandlerFunc {
|
func reloadRules(c *Config) http.HandlerFunc {
|
||||||
|
@ -20,7 +23,12 @@ func reloadRules(c *Config) http.HandlerFunc {
|
||||||
http.Error(w, e.Error(), http.StatusInternalServerError)
|
http.Error(w, e.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
w.Write([]byte("ok"))
|
_, err = w.Write([]byte("ok"))
|
||||||
|
if err != nil {
|
||||||
|
e := fmt.Errorf("cannot reload rules: %+v", err)
|
||||||
|
http.Error(w, e.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,7 +47,11 @@ func serveRules(c *Config) http.HandlerFunc {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
w.Write(data)
|
_, err = w.Write(data)
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,7 +83,11 @@ func serveRules(c *Config) http.HandlerFunc {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
w.Write(data)
|
_, err = w.Write(data)
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,6 +110,10 @@ func serveRules(c *Config) http.HandlerFunc {
|
||||||
}
|
}
|
||||||
|
|
||||||
w.Header().Set("Cache-Control", "public, max-age=500")
|
w.Header().Set("Cache-Control", "public, max-age=500")
|
||||||
w.Write(buf.Bytes())
|
_, err = w.Write(buf.Bytes())
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
7
main.go
7
main.go
|
@ -52,7 +52,12 @@ func main() {
|
||||||
|
|
||||||
confFlag := flags.String("conf", "", "Required. Contains all the configurations options")
|
confFlag := flags.String("conf", "", "Required. Contains all the configurations options")
|
||||||
|
|
||||||
flags.Parse(os.Args[1:])
|
err := flags.Parse(os.Args[1:])
|
||||||
|
if err != nil {
|
||||||
|
errorLog.Println("Error: cannot parse command-line arguments")
|
||||||
|
flags.Usage()
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
if len(flags.Args()) > 1 {
|
if len(flags.Args()) > 1 {
|
||||||
errorLog.Println("Error: too many command-line arguments")
|
errorLog.Println("Error: too many command-line arguments")
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -9,7 +10,10 @@ import (
|
||||||
func serveLogger(l *LogFile) func(http.HandlerFunc) http.HandlerFunc {
|
func serveLogger(l *LogFile) func(http.HandlerFunc) http.HandlerFunc {
|
||||||
return func(next http.HandlerFunc) http.HandlerFunc {
|
return func(next http.HandlerFunc) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
l.WriteLog(r)
|
err := l.WriteLog(r)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("Error writing log : %+v", err)
|
||||||
|
}
|
||||||
next(w, r)
|
next(w, r)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -113,12 +113,12 @@ func walkMatch(t *testing.T, root, pattern string) []string {
|
||||||
// return !errors.Is(err, fs.ErrNotExist)
|
// return !errors.Is(err, fs.ErrNotExist)
|
||||||
// }
|
// }
|
||||||
|
|
||||||
func removeFileForTest(t *testing.T, name string) {
|
// func removeFileForTest(t *testing.T, name string) {
|
||||||
err := os.Remove(name)
|
// err := os.Remove(name)
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
t.Fatal(err)
|
// t.Fatal(err)
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
func writeJsonForTest(t *testing.T, data map[string]any, fp string) {
|
func writeJsonForTest(t *testing.T, data map[string]any, fp string) {
|
||||||
jsonString, _ := json.Marshal(data)
|
jsonString, _ := json.Marshal(data)
|
||||||
|
|
Loading…
Reference in New Issue