diff --git a/Dockerfile b/Dockerfile index 2589a5c..2b95f9c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -34,9 +34,7 @@ RUN chmod 777 /config; \ WORKDIR /api COPY --from=builder /api/app . -COPY client ./client -COPY webassets ./webassets EXPOSE 8080 -ENTRYPOINT ["./app"] \ No newline at end of file +ENTRYPOINT ["./app"] diff --git a/docs/ubuntu-install.md b/docs/ubuntu-install.md index bfd6d27..33dc47a 100644 --- a/docs/ubuntu-install.md +++ b/docs/ubuntu-install.md @@ -6,7 +6,7 @@ This guide has been written with Ubuntu in mind. If you are using any other flav ## Install Go -Podgrab is built using Go which would be needed to compile and build the source code. Podgrab is written with Go 1.15 so any version equal to or above this should be good to Go. +Podgrab is built using Go which would be needed to compile and build the source code. Podgrab is written with Go 1.16 so any version equal to or above this should be good to Go. If you already have Go installed on your machine, you can skip to the next step. @@ -31,8 +31,6 @@ git clone --depth 1 https://github.com/akhilrex/podgrab ``` bash cd podgrab mkdir -p ./dist -cp -r client ./dist -cp -r webassets ./dist cp .env ./dist go build -o ./dist/podgrab ./main.go ``` diff --git a/go.mod b/go.mod index 68da40a..1371ffa 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/akhilrex/podgrab -go 1.15 +go 1.16 require ( github.com/TheHippo/podcastindex v1.0.0 diff --git a/main.go b/main.go index 426c820..6b09d95 100644 --- a/main.go +++ b/main.go @@ -1,9 +1,12 @@ package main import ( + "embed" "fmt" "html/template" + "io/fs" "log" + "net/http" "os" "path" "strconv" @@ -18,6 +21,13 @@ import ( _ "github.com/joho/godotenv/autoload" ) +var ( + //go:embed client + clientEmbed embed.FS + //go:embed webassets + webAssetsEmbed embed.FS +) + func main() { var err error db.DB, err = db.Init() @@ -127,7 +137,7 @@ func main() { return fmt.Sprintf("%02d:%02d", mins, secs) }, } - tmpl := template.Must(template.New("main").Funcs(funcMap).ParseGlob("client/*")) + tmpl := template.Must(template.New("main").Funcs(funcMap).ParseFS(clientEmbed, "client/*")) //r.LoadHTMLGlob("client/*") r.SetHTMLTemplate(tmpl) @@ -145,7 +155,12 @@ func main() { dataPath := os.Getenv("DATA") backupPath := path.Join(os.Getenv("CONFIG"), "backups") - router.Static("/webassets", "./webassets") + webAssets, err := fs.Sub(webAssetsEmbed, "webassets") + if err != nil { + log.Fatal(err) + } + + router.StaticFS("/webassets", http.FS(webAssets)) router.Static("/assets", dataPath) router.Static(backupPath, backupPath) router.POST("/podcasts", controllers.AddPodcast)