65 lines
1.5 KiB
Go
65 lines
1.5 KiB
Go
package main
|
|
|
|
import (
|
|
"dwelling-upload/internal/configuration"
|
|
"dwelling-upload/internal/handlers"
|
|
"dwelling-upload/pkg/logging"
|
|
"dwelling-upload/pkg/server"
|
|
"flag"
|
|
"log"
|
|
"net/http"
|
|
"os"
|
|
"os/signal"
|
|
"syscall"
|
|
)
|
|
|
|
var configPath *string = flag.String("conf", "config.yaml", "path to configuration file")
|
|
|
|
func main() {
|
|
flag.Parse()
|
|
|
|
config, err := configuration.LoadConfiguration(*configPath)
|
|
if err != nil {
|
|
log.Fatalln(err)
|
|
}
|
|
|
|
logErr, err := logging.NewLogger(config.LogDir + "/error.log")
|
|
if err != nil {
|
|
log.Fatalln("failed to open error logger:", err)
|
|
}
|
|
defer logErr.Close()
|
|
|
|
logUpload, err := logging.NewLogger(config.LogDir + "/upload.log")
|
|
if err != nil {
|
|
log.Fatalln("failed to open upload logger:", err)
|
|
}
|
|
defer logUpload.Close()
|
|
|
|
logDownload, err := logging.NewLogger(config.LogDir + "/download.log")
|
|
if err != nil {
|
|
log.Fatalln("failed to open download logger:", err)
|
|
}
|
|
defer logDownload.Close()
|
|
|
|
hand := handlers.NewUploadHandlers(config, logErr, logUpload, logDownload)
|
|
srv := server.NewHttpServer()
|
|
|
|
srv.ServeStatic("/assets/*filepath", http.Dir(config.WebDir+"/assets"))
|
|
srv.GET("/", hand.Index)
|
|
srv.POST("/", hand.Upload)
|
|
srv.GET("/f/:hash/:name", hand.Download)
|
|
|
|
if err := srv.Start(config.SplitNetworkAddress()); err != nil {
|
|
logErr.Fatalln(err)
|
|
}
|
|
|
|
doneSignal := make(chan os.Signal, 1)
|
|
signal.Notify(doneSignal, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
|
|
|
|
<-doneSignal
|
|
|
|
if err := srv.Stop(); err != nil {
|
|
logErr.Fatalln(err)
|
|
}
|
|
}
|