Added flags that replace config file.
This commit is contained in:
parent
470bbb04ee
commit
11dfbfbc23
@ -1,7 +1,6 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"dwelling-upload/internal/configuration"
|
||||
"dwelling-upload/internal/http"
|
||||
"dwelling-upload/pkg/logging"
|
||||
"dwelling-upload/pkg/utils"
|
||||
@ -12,12 +11,17 @@ import (
|
||||
"net/netip"
|
||||
"os"
|
||||
"os/signal"
|
||||
"path"
|
||||
"strings"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
var configPath *string = flag.String("conf", "config.yaml", "path to configuration file")
|
||||
var listenAddress *string = flag.String("listen", "/var/run/dwelling-upload/sock", "listen address (ip:port|unix_path)")
|
||||
var uploadDir *string = flag.String("upload-dir", "/srv/uploads", "path to a directory where uploaded files are stored")
|
||||
var keepFileForHours *int64 = flag.Int64("keep-for", 36, "keep files for this much hours")
|
||||
var limitStorage *int64 = flag.Int64("storage", 102400, "storage size in MiB for uploads")
|
||||
var limitFileSize *int64 = flag.Int64("file-size", 128, "max. size in MiB for uploaded files")
|
||||
var showVersion *bool = flag.Bool("v", false, "show version")
|
||||
|
||||
var version string
|
||||
@ -31,11 +35,6 @@ func main() {
|
||||
return
|
||||
}
|
||||
|
||||
config, err := configuration.LoadConfiguration(*configPath)
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
||||
var network string
|
||||
if !strings.ContainsRune(*listenAddress, ':') {
|
||||
network = "unix"
|
||||
@ -68,14 +67,14 @@ func main() {
|
||||
}
|
||||
defer watcha.Close()
|
||||
|
||||
if err := watcha.AddWatch(config.Uploads.Directory, watcher.CrDelMask); err != nil {
|
||||
if err := watcha.AddWatch(*uploadDir, watcher.CrDelMask); err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
||||
uploadDirNotify := make(chan uint32)
|
||||
uploadDirSize, err := utils.DirectorySize(config.Uploads.Directory)
|
||||
uploadDirSize, err := utils.DirectorySize(*uploadDir)
|
||||
if err != nil {
|
||||
log.Fatalf("failed to get initial size of %s: %s", config.Uploads.Directory, err)
|
||||
log.Fatalf("failed to get initial size of %s: %s", *uploadDir, err)
|
||||
}
|
||||
|
||||
watcha.WatchForMask(uploadDirNotify, watcher.CrDelMask)
|
||||
@ -110,7 +109,7 @@ func main() {
|
||||
case <-logReopenSignal:
|
||||
logFile.Reopen(logFilePath)
|
||||
case <-uploadDirNotify:
|
||||
uploadDirSize, err = utils.DirectorySize(config.Uploads.Directory)
|
||||
uploadDirSize, err = utils.DirectorySize(*uploadDir)
|
||||
if err != nil {
|
||||
log.Println("failed to get uploads directory size:", err)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user