Reorginised the main()'s code a little.
This commit is contained in:
parent
949c2e68c8
commit
2d4169245c
@ -57,6 +57,19 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
watcha, err := watcher.NewInotifyWatcher()
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
defer watcha.Close()
|
||||
|
||||
if err := watcha.AddWatch(*uploadDir, watcher.CrDelMask); err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
||||
uploadDirNotify := make(chan uint32)
|
||||
go watcha.WatchForMask(uploadDirNotify, watcher.CrDelMask)
|
||||
|
||||
hashSalt, err := os.ReadFile(path.Join(os.Getenv("CREDENTIALS_DIRECTORY"), "salt"))
|
||||
if err != nil {
|
||||
log.Fatalln("failed to read hash salt file:", err)
|
||||
@ -72,24 +85,11 @@ func main() {
|
||||
|
||||
logFile := log.New(logFileFd, "", log.LstdFlags)
|
||||
|
||||
watcha, err := watcher.NewInotifyWatcher()
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
defer watcha.Close()
|
||||
|
||||
if err := watcha.AddWatch(*uploadDir, watcher.CrDelMask); err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
||||
uploadDirNotify := make(chan uint32)
|
||||
uploadDirSize, err := utils.DirectorySize(*uploadDir)
|
||||
if err != nil {
|
||||
log.Fatalf("failed to get initial size of %s: %s", *uploadDir, err)
|
||||
}
|
||||
|
||||
go watcha.WatchForMask(uploadDirNotify, watcher.CrDelMask)
|
||||
|
||||
hand := http.NewUploadHandlers(logFile, *uploadDir, &uploadDirSize, string(hashSalt),
|
||||
*keepForHours, *storageSize, *fileSizeLimit)
|
||||
|
||||
@ -110,6 +110,11 @@ func main() {
|
||||
r.Handler(nethttp.MethodGet, "/favicon.svg", http.Favicon)
|
||||
|
||||
srv := http.NewHttpServer(r)
|
||||
defer func() {
|
||||
if err := srv.Stop(); err != nil {
|
||||
log.Fatalln("failed to properly shutdown a server:", err)
|
||||
}
|
||||
}()
|
||||
|
||||
if err := srv.Start(network, *listenAddress); err != nil {
|
||||
log.Fatalln("failed to start a server:", err)
|
||||
@ -131,8 +136,4 @@ func main() {
|
||||
}()
|
||||
|
||||
<-doneSignal
|
||||
|
||||
if err := srv.Stop(); err != nil {
|
||||
log.Fatalln("failed to properly shutdown a server:", err)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user