1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- package main
- import (
- "embed"
- "flag"
- "fmt"
- "io/fs"
- "net/http"
- "os"
- "imuslab.com/bokofs/bokofsd/mod/bokofs"
- "imuslab.com/bokofs/bokofsd/mod/bokofs/bokoworker"
- )
- //go:embed web/*
- var embeddedFiles embed.FS
- func main() {
- flag.Parse()
- var fileSystem http.FileSystem
- if *devMode {
- fmt.Println("Development mode enabled. Serving files from ./web directory.")
- fileSystem = http.Dir("./web")
- } else {
- fmt.Println("Production mode enabled. Serving files from embedded filesystem.")
- subFS, err := fs.Sub(embeddedFiles, "web")
- if err != nil {
- fmt.Fprintf(os.Stderr, "Error accessing embedded subdirectory: %v\n", err)
- os.Exit(1)
- }
- fileSystem = http.FS(subFS)
- }
- configFolderPath := "./config"
- if *config != "" {
- configFolderPath = *config
- }
- if _, err := os.Stat(configFolderPath); os.IsNotExist(err) {
- fmt.Printf("Config folder does not exist. Creating folder at %s\n", configFolderPath)
- if err := os.Mkdir(configFolderPath, os.ModePerm); err != nil {
- fmt.Fprintf(os.Stderr, "Error creating config folder: %v\n", err)
- os.Exit(1)
- }
- }
- //DEBUG
- wds, err := bokofs.NewWebdavInterfaceServer("/disk/")
- if err != nil {
- panic(err)
- }
- test, err := bokoworker.NewWorker("test", "./web")
- if err != nil {
- panic(err)
- }
- wds.AddWorker(test)
- test2, err := bokoworker.NewWorker("test2", "./mod")
- if err != nil {
- panic(err)
- }
- wds.AddWorker(test2)
- http.Handle("/", http.FileServer(fileSystem))
- http.Handle("/disk/", wds.Handler())
- http.Handle("/meta", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
- // TODO: Implement handler logic for /meta
- fmt.Fprintln(w, "Meta handler not implemented yet")
- }))
- http.Handle("/cache", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
- // TODO: Implement handler logic for /cache
- fmt.Fprintln(w, "Cache handler not implemented yet")
- }))
- http.Handle("/thumb", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
- // TODO: Implement handler logic for /thumb
- fmt.Fprintln(w, "Thumb handler not implemented yet")
- }))
- addr := fmt.Sprintf(":%d", *httpPort)
- fmt.Printf("Starting static web server on %s\n", addr)
- if err := http.ListenAndServe(addr, nil); err != nil {
- fmt.Fprintf(os.Stderr, "Error starting server: %v\n", err)
- os.Exit(1)
- }
- }
|