mirror of
https://github.com/nxshock/promodj.git
synced 2025-07-01 23:53:35 +05:00
Initial commit
This commit is contained in:
commit
01138252ac
16 changed files with 1195 additions and 0 deletions
66
main.go
Normal file
66
main.go
Normal file
|
@ -0,0 +1,66 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"html/template"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
_ "embed"
|
||||
)
|
||||
|
||||
//go:embed templates/genres.html
|
||||
var templateBytes embed.FS
|
||||
|
||||
var templates *template.Template
|
||||
|
||||
func init() {
|
||||
log.SetFlags(0)
|
||||
|
||||
if len(os.Args) == 2 {
|
||||
if err := initConfig(os.Args[1]); err != nil {
|
||||
log.Fatalln("config error:", err)
|
||||
}
|
||||
} else {
|
||||
if err := initConfig(defaultConfigFilePath); err != nil {
|
||||
log.Fatalln("config error:", err)
|
||||
}
|
||||
}
|
||||
|
||||
err := initTepmplates()
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
||||
err = UpdateGenres()
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
||||
http.DefaultClient.Timeout = 5 * time.Second
|
||||
}
|
||||
|
||||
func initTepmplates() error {
|
||||
var err error
|
||||
|
||||
templates, err = template.ParseFS(templateBytes, "templates/*.html")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func main() {
|
||||
http.HandleFunc("/", handleGenres)
|
||||
http.HandleFunc("/genres", handleGenres)
|
||||
http.HandleFunc("/getm3u", handleGetM3u)
|
||||
http.HandleFunc("/stream", handleStream)
|
||||
|
||||
err := http.ListenAndServe(config.ListenAddr, nil)
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue