Embed HTML
This commit is contained in:
BIN
dist/fitra-darwin-amd64
vendored
BIN
dist/fitra-darwin-amd64
vendored
Binary file not shown.
BIN
dist/fitra-darwin-arm64
vendored
BIN
dist/fitra-darwin-arm64
vendored
Binary file not shown.
BIN
dist/fitra-linux-amd64
vendored
BIN
dist/fitra-linux-amd64
vendored
Binary file not shown.
BIN
dist/fitra-linux-arm64
vendored
BIN
dist/fitra-linux-arm64
vendored
Binary file not shown.
9
main.go
9
main.go
@@ -1,9 +1,11 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"embed"
|
||||||
"fitra-backend/application"
|
"fitra-backend/application"
|
||||||
"fitra-backend/controllers"
|
"fitra-backend/controllers"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"html/template"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
@@ -11,6 +13,9 @@ import (
|
|||||||
"github.com/joho/godotenv"
|
"github.com/joho/godotenv"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//go:embed views/*
|
||||||
|
var viewsFS embed.FS
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
if err := godotenv.Load(); err != nil {
|
if err := godotenv.Load(); err != nil {
|
||||||
log.Println("No .env file found")
|
log.Println("No .env file found")
|
||||||
@@ -19,7 +24,9 @@ func main() {
|
|||||||
go application.StartCleanupRoutine()
|
go application.StartCleanupRoutine()
|
||||||
|
|
||||||
r := gin.Default()
|
r := gin.Default()
|
||||||
r.LoadHTMLGlob("views/*")
|
|
||||||
|
tmpl := template.Must(template.New("").ParseFS(viewsFS, "views/*.html"))
|
||||||
|
r.SetHTMLTemplate(tmpl)
|
||||||
|
|
||||||
r.GET("/", controllers.HandleIndex)
|
r.GET("/", controllers.HandleIndex)
|
||||||
r.POST("/upload", controllers.HandleFileUpload)
|
r.POST("/upload", controllers.HandleFileUpload)
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ curl -O {{.BaseURL}}/uploads/abc123.../myfile.txt</code></pre>
|
|||||||
<script>
|
<script>
|
||||||
async function loadStorageInfo() {
|
async function loadStorageInfo() {
|
||||||
try {
|
try {
|
||||||
const response = await fetch('{{.BaseURL}}/storage');
|
const response = await fetch('/storage');
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
const storage = data.storage;
|
const storage = data.storage;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user