turns out rewriting all of your database code takes a while
This commit is contained in:
parent
1998a36d6d
commit
965d6f5c3e
30 changed files with 947 additions and 1036 deletions
|
@ -5,7 +5,6 @@ import (
|
|||
"os"
|
||||
"strings"
|
||||
|
||||
"arimelody.me/arimelody.me/music/model"
|
||||
"github.com/jmoiron/sqlx"
|
||||
)
|
||||
|
||||
|
@ -44,34 +43,3 @@ var HTTP_DOMAIN = func() string {
|
|||
}()
|
||||
|
||||
var DB *sqlx.DB
|
||||
|
||||
var Releases []*model.Release
|
||||
var Artists []*model.Artist
|
||||
var Tracks []*model.Track
|
||||
|
||||
func GetRelease(id string) *model.Release {
|
||||
for _, release := range Releases {
|
||||
if release.ID == id {
|
||||
return release
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func GetArtist(id string) *model.Artist {
|
||||
for _, artist := range Artists {
|
||||
if artist.ID == id {
|
||||
return artist
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func GetTrack(id string) *model.Track {
|
||||
for _, track := range Tracks {
|
||||
if track.ID == id {
|
||||
return track
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -3,9 +3,6 @@ package global
|
|||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"html/template"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
|
@ -64,39 +61,3 @@ func HTTPLog(next http.Handler) http.Handler {
|
|||
})
|
||||
}
|
||||
|
||||
func ServeTemplate(page string, data any) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
lp_layout := filepath.Join("views", "layout.html")
|
||||
lp_header := filepath.Join("views", "header.html")
|
||||
lp_footer := filepath.Join("views", "footer.html")
|
||||
lp_prideflag := filepath.Join("views", "prideflag.html")
|
||||
fp := filepath.Join("views", filepath.Clean(page))
|
||||
|
||||
info, err := os.Stat(fp)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if info.IsDir() {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
template, err := template.ParseFiles(lp_layout, lp_header, lp_footer, lp_prideflag, fp)
|
||||
if err != nil {
|
||||
fmt.Printf("Error parsing template files: %s\n", err)
|
||||
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
err = template.ExecuteTemplate(w, "layout.html", data)
|
||||
if err != nil {
|
||||
fmt.Printf("Error executing template: %s\n", err)
|
||||
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue