36 lines
607 B
Go
36 lines
607 B
Go
package main
|
|
|
|
import (
|
|
"html/template"
|
|
"log"
|
|
"net/http"
|
|
"os"
|
|
|
|
"github.com/joho/godotenv"
|
|
)
|
|
|
|
var tpl = template.Must(template.ParseFiles("index.html"))
|
|
|
|
func indexHandler(w http.ResponseWriter, r *http.Request) {
|
|
tpl.Execute(w, nil)
|
|
}
|
|
|
|
func main() {
|
|
err := godotenv.Load()
|
|
if err != nil {
|
|
log.Println("Error loading .env file")
|
|
}
|
|
|
|
port := os.Getenv("PORT")
|
|
if port == "" {
|
|
port = "3000"
|
|
}
|
|
|
|
fs := http.FileServer(http.Dir("assets"))
|
|
|
|
mux := http.NewServeMux()
|
|
mux.Handle("/assets/", http.StripPrefix("/assets/", fs))
|
|
mux.HandleFunc("/", indexHandler)
|
|
http.ListenAndServe(":"+port, mux)
|
|
}
|