1
0

Added flags that replace config file.

This commit is contained in:
Alexander Andreev 2023-05-24 22:11:28 +04:00
parent 470bbb04ee
commit 11dfbfbc23
Signed by: Arav
GPG Key ID: D22A817D95815393

View File

@ -1,7 +1,6 @@
package main package main
import ( import (
"dwelling-upload/internal/configuration"
"dwelling-upload/internal/http" "dwelling-upload/internal/http"
"dwelling-upload/pkg/logging" "dwelling-upload/pkg/logging"
"dwelling-upload/pkg/utils" "dwelling-upload/pkg/utils"
@ -12,12 +11,17 @@ import (
"net/netip" "net/netip"
"os" "os"
"os/signal" "os/signal"
"path"
"strings" "strings"
"syscall" "syscall"
) )
var configPath *string = flag.String("conf", "config.yaml", "path to configuration file") 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 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 showVersion *bool = flag.Bool("v", false, "show version")
var version string var version string
@ -31,11 +35,6 @@ func main() {
return return
} }
config, err := configuration.LoadConfiguration(*configPath)
if err != nil {
log.Fatalln(err)
}
var network string var network string
if !strings.ContainsRune(*listenAddress, ':') { if !strings.ContainsRune(*listenAddress, ':') {
network = "unix" network = "unix"
@ -68,14 +67,14 @@ func main() {
} }
defer watcha.Close() 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) log.Fatalln(err)
} }
uploadDirNotify := make(chan uint32) uploadDirNotify := make(chan uint32)
uploadDirSize, err := utils.DirectorySize(config.Uploads.Directory) uploadDirSize, err := utils.DirectorySize(*uploadDir)
if err != nil { 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) watcha.WatchForMask(uploadDirNotify, watcher.CrDelMask)
@ -110,7 +109,7 @@ func main() {
case <-logReopenSignal: case <-logReopenSignal:
logFile.Reopen(logFilePath) logFile.Reopen(logFilePath)
case <-uploadDirNotify: case <-uploadDirNotify:
uploadDirSize, err = utils.DirectorySize(config.Uploads.Directory) uploadDirSize, err = utils.DirectorySize(*uploadDir)
if err != nil { if err != nil {
log.Println("failed to get uploads directory size:", err) log.Println("failed to get uploads directory size:", err)
} }