Files
filehost-athome/main.go
T
odonax 64e5c26bc0 Implemented configuration file functionality
For site name, port number and data directory
2026-04-29 22:08:23 +02:00

37 lines
777 B
Go

package main
import (
"html/template"
"log"
"net/http"
"os"
"192.168.1.180/odonax/filehost-athome/config"
"192.168.1.180/odonax/filehost-athome/database"
)
func main() {
cfg := config.Load("config.json")
os.MkdirAll(cfg.DataDir+"/files", 0755)
db := database.Open(cfg.DataDir+"/hub.db")
defer db.Close()
tmpl, err := template.ParseFiles("templates/home.html")
if err != nil {
log.Fatal("Failed to load template:", err)
}
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
data := map[string]string{
"Name": cfg.SiteName,
"Description": "This is where you'll own your files and share them freely.",
}
tmpl.Execute(w, data)
})
log.Println("Starting filehost on :8080")
log.Fatal(http.ListenAndServe(":8080", nil))
}