chore: upgrade to go1.24
This commit is contained in:
parent
50784a6ab5
commit
0474c2dcb6
@ -47,7 +47,7 @@ func annotations(l *utils.Logger) http.HandlerFunc {
|
|||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
_, err = buf.ReadFrom(resp.Body)
|
_, err = buf.ReadFrom(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
l.Error("Error paring genius api response: %s", err.Error())
|
l.Errorf("Error paring genius api response: %s", err.Error())
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
utils.RenderTemplate(w, views.ErrorPage(500, "something went wrong"), l)
|
utils.RenderTemplate(w, views.ErrorPage(500, "something went wrong"), l)
|
||||||
return
|
return
|
||||||
@ -56,7 +56,7 @@ func annotations(l *utils.Logger) http.HandlerFunc {
|
|||||||
var data data.AnnotationsResponse
|
var data data.AnnotationsResponse
|
||||||
err = json.Unmarshal(buf.Bytes(), &data)
|
err = json.Unmarshal(buf.Bytes(), &data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
l.Error("could not unmarshal json: %s\n", err)
|
l.Errorf("could not unmarshal json: %s\n", err)
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
utils.RenderTemplate(w, views.ErrorPage(500, "something went wrong"), l)
|
utils.RenderTemplate(w, views.ErrorPage(500, "something went wrong"), l)
|
||||||
return
|
return
|
||||||
@ -69,7 +69,7 @@ func annotations(l *utils.Logger) http.HandlerFunc {
|
|||||||
encoder := json.NewEncoder(w)
|
encoder := json.NewEncoder(w)
|
||||||
|
|
||||||
if err = encoder.Encode(&annotation); err != nil {
|
if err = encoder.Encode(&annotation); err != nil {
|
||||||
l.Error("Error sending response: %s", err.Error())
|
l.Errorf("Error sending response: %s", err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@ func imageProxy(l *utils.Logger) http.HandlerFunc {
|
|||||||
w.Header().Set("Content-type", mime.TypeByExtension("."+ext))
|
w.Header().Set("Content-type", mime.TypeByExtension("."+ext))
|
||||||
w.Header().Add("Cache-Control", "max-age=1296000")
|
w.Header().Add("Cache-Control", "max-age=1296000")
|
||||||
if _, err = io.Copy(w, res.Body); err != nil {
|
if _, err = io.Copy(w, res.Body); err != nil {
|
||||||
l.Error("unable to write image, %s", err.Error())
|
l.Errorf("unable to write image, %s", err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
4
main.go
4
main.go
@ -39,7 +39,7 @@ func main() {
|
|||||||
|
|
||||||
if port == 0 {
|
if port == 0 {
|
||||||
port = 5555
|
port = 5555
|
||||||
logger.Info("using default port %d", port)
|
logger.Infof("using default port %d", port)
|
||||||
}
|
}
|
||||||
|
|
||||||
l, err := net.Listen("tcp", fmt.Sprintf(":%d", port))
|
l, err := net.Listen("tcp", fmt.Sprintf(":%d", port))
|
||||||
@ -47,7 +47,7 @@ func main() {
|
|||||||
logger.Fatal(err.Error())
|
logger.Fatal(err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.Info("server is listening on port %d", port)
|
logger.Infof("server is listening on port %d", port)
|
||||||
|
|
||||||
if err := server.Serve(l); err != nil {
|
if err := server.Serve(l); err != nil {
|
||||||
logger.Fatal(err.Error())
|
logger.Fatal(err.Error())
|
||||||
|
@ -18,15 +18,27 @@ func NewLogger(w io.WriteCloser) *Logger {
|
|||||||
return &Logger{slog: sl}
|
return &Logger{slog: sl}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *Logger) Error(f string, args ...any) {
|
func (l *Logger) Errorf(f string, args ...any) {
|
||||||
l.slog.Error(fmt.Sprintf(f, args...))
|
l.slog.Error(fmt.Sprintf(f, args...))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *Logger) Info(f string, args ...any) {
|
func (l *Logger) Error(e string) {
|
||||||
|
l.Errorf("%s", e)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *Logger) Infof(f string, args ...any) {
|
||||||
l.slog.Info(fmt.Sprintf(f, args...))
|
l.slog.Info(fmt.Sprintf(f, args...))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *Logger) Fatal(f string, args ...any) {
|
func (l *Logger) Info(m string) {
|
||||||
l.Error(f, args...)
|
l.Infof("%s", m)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *Logger) Fatalf(f string, args ...any) {
|
||||||
|
l.Errorf(f, args...)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (l *Logger) Fatal(e string) {
|
||||||
|
l.Fatalf("%s", e)
|
||||||
|
}
|
||||||
|
@ -9,7 +9,7 @@ import (
|
|||||||
|
|
||||||
func RenderTemplate(w http.ResponseWriter, t templ.Component, l *Logger) {
|
func RenderTemplate(w http.ResponseWriter, t templ.Component, l *Logger) {
|
||||||
if err := t.Render(context.Background(), w); err != nil {
|
if err := t.Render(context.Background(), w); err != nil {
|
||||||
l.Error("unable to render template %s", err)
|
l.Errorf("unable to render template %s", err)
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
_, err := w.Write([]byte{})
|
_, err := w.Write([]byte{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user