add caching and change the layout a bit

This commit is contained in:
rramiachraf
2022-07-01 23:40:13 +01:00
parent 7b2c43cc16
commit e7aa7403c7
8 changed files with 114 additions and 29 deletions

23
main.go
View File

@ -2,32 +2,27 @@ package main
import (
"fmt"
"log"
"net"
"net/http"
"os"
"strconv"
"time"
"github.com/allegro/bigcache/v3"
"github.com/gorilla/mux"
)
func fatal(err any) {
log.Fatalf("[ERR] %s\n", err)
}
func info(s string) {
log.Printf("[INFO] %s\n", s)
}
func write(w http.ResponseWriter, status int, data []byte) {
w.WriteHeader(status)
w.Write(data)
}
func main() {
c, err := bigcache.NewBigCache(bigcache.DefaultConfig(time.Hour * 2))
if err != nil {
fatal("can't initialize caching")
}
cache = c
r := mux.NewRouter()
r.Use(securityHeaders)
r.HandleFunc("/{id}-lyrics", lyricsHandler)
r.PathPrefix("/static/").Handler(http.StripPrefix("/static/", http.FileServer(http.Dir("static"))))