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
35
main.go
35
main.go
|
@ -11,8 +11,8 @@ import (
|
|||
"arimelody.me/arimelody.me/admin"
|
||||
"arimelody.me/arimelody.me/api"
|
||||
"arimelody.me/arimelody.me/global"
|
||||
musicController "arimelody.me/arimelody.me/music/controller"
|
||||
musicView "arimelody.me/arimelody.me/music/view"
|
||||
"arimelody.me/arimelody.me/templates"
|
||||
|
||||
"github.com/jmoiron/sqlx"
|
||||
_ "github.com/lib/pq"
|
||||
|
@ -25,42 +25,18 @@ func main() {
|
|||
var err error
|
||||
global.DB, err = sqlx.Connect("postgres", "user=arimelody dbname=arimelody password=fuckingpassword sslmode=disable")
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "unable to create database connection pool: %v\n", err)
|
||||
fmt.Fprintf(os.Stderr, "FATAL: Unable to create database connection pool: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
global.DB.SetConnMaxLifetime(time.Minute * 3)
|
||||
global.DB.SetMaxOpenConns(10)
|
||||
global.DB.SetMaxIdleConns(10)
|
||||
defer global.DB.Close()
|
||||
|
||||
// pull artist data from DB
|
||||
global.Artists, err = musicController.PullAllArtists(global.DB)
|
||||
if err != nil {
|
||||
fmt.Printf("Failed to pull artists from database: %v\n", err);
|
||||
panic(1)
|
||||
}
|
||||
fmt.Printf("%d artists loaded successfully.\n", len(global.Artists))
|
||||
|
||||
// pull track data from DB
|
||||
global.Tracks, err = musicController.PullAllTracks(global.DB)
|
||||
if err != nil {
|
||||
fmt.Printf("Failed to pull tracks from database: %v\n", err);
|
||||
panic(1)
|
||||
}
|
||||
fmt.Printf("%d tracks loaded successfully.\n", len(global.Tracks))
|
||||
|
||||
// pull release data from DB
|
||||
global.Releases, err = musicController.PullAllReleases(global.DB)
|
||||
if err != nil {
|
||||
fmt.Printf("Failed to pull releases from database: %v\n", err);
|
||||
panic(1)
|
||||
}
|
||||
fmt.Printf("%d releases loaded successfully.\n", len(global.Releases))
|
||||
|
||||
// start the web server!
|
||||
mux := createServeMux()
|
||||
port := DEFAULT_PORT
|
||||
fmt.Printf("now serving at http://127.0.0.1:%d\n", port)
|
||||
fmt.Printf("Now serving at http://127.0.0.1:%d\n", port)
|
||||
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", port), global.HTTPLog(mux)))
|
||||
}
|
||||
|
||||
|
@ -73,7 +49,10 @@ func createServeMux() *http.ServeMux {
|
|||
mux.Handle("/uploads/", http.StripPrefix("/uploads", staticHandler("uploads")))
|
||||
mux.Handle("/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.URL.Path == "/" || r.URL.Path == "/index.html" {
|
||||
global.ServeTemplate("index.html", nil).ServeHTTP(w, r)
|
||||
err := templates.Pages["index"].Execute(w, nil)
|
||||
if err != nil {
|
||||
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||
}
|
||||
return
|
||||
}
|
||||
staticHandler("public").ServeHTTP(w, r)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue