[WIP] settings up template and static files embedding

This commit is contained in:
HeshamTB 2023-09-11 20:54:28 +03:00
parent 598fd51412
commit 5c7bfc21ed
4 changed files with 22 additions and 1 deletions

3
go.mod Normal file
View File

@ -0,0 +1,3 @@
module gitea.hbanafa.com/hesham/viddl
go 1.21.0

11
main.go
View File

@ -1,6 +1,7 @@
package main package main
import ( import (
"embed"
"encoding/json" "encoding/json"
"fmt" "fmt"
"html/template" "html/template"
@ -8,6 +9,8 @@ import (
"log" "log"
"net/http" "net/http"
"time" "time"
"gitea.hbanafa.com/hesham/viddl/resources"
) )
const ( const (
@ -77,6 +80,14 @@ func writeJSONResponse(w http.ResponseWriter, s string) http.ResponseWriter {
} }
var templates *template.Template
func init() {
log.Println("[ init ] Starting...")
templates = template.Must(template.ParseFS(resources.TemplatesFS, "templates/*.html"))
}
func main() { func main() {
handler := http.NewServeMux() handler := http.NewServeMux()

7
resources/resources.go Normal file
View File

@ -0,0 +1,7 @@
package resources
import "embed"
//go:embed gitea.hbanafa.com/hesham/viddl/resources
var TemplatesFS embed.FS

View File

@ -1 +1 @@
<a href="{{ . }}" rel="nofollow" download>Download</a> <a href="{{ . }}" rel="" download target="_blank">Download</a>