From bd1ebe51860cca7eab8c127df585d354efb85192 Mon Sep 17 00:00:00 2001 From: stefanbenten Date: Sun, 29 Mar 2020 18:29:00 +0200 Subject: [PATCH] further simplifying --- README.md | 2 +- cmd/cmd.go | 24 ++-------- server/server.go | 95 ++++++++++++++++++++-------------------- server/utils/template.go | 17 +++++++ 4 files changed, 70 insertions(+), 68 deletions(-) create mode 100644 server/utils/template.go diff --git a/README.md b/README.md index df3591b..7d9fc19 100644 --- a/README.md +++ b/README.md @@ -105,7 +105,7 @@ basedir | path storage for local/gdrive provider| | cleanup-interval | interval to clean up expired files from local storage | 1 | gdrive-client-json-filepath | path to oauth client json config for gdrive provider| | gdrive-local-config-path | path to store local transfer.sh config cache for gdrive provider| | -gdrive-chunk-size | chunk size for gdrive upload in megabytes, must be lower than available memory (8 MB) | | +gdrive-chunk-size | chunk size for gdrive upload in megabytes, must be lower than available memory | 16 | lets-encrypt-hosts | hosts to use for lets encrypt certificates (comma seperated) | | log | path to log file| | diff --git a/cmd/cmd.go b/cmd/cmd.go index 11836e8..d603c5a 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -11,25 +11,9 @@ import ( "github.com/dutchcoders/transfer.sh/server/utils" "github.com/fatih/color" "github.com/urfave/cli" - "google.golang.org/api/googleapi" ) -var Version = "1.1.4" -var helpTemplate = `NAME: -{{.Name}} - {{.Usage}} - -DESCRIPTION: -{{.Description}} - -USAGE: -{{.Name}} {{if .Flags}}[flags] {{end}}command{{if .Flags}}{{end}} [arguments...] - -COMMANDS: -{{range .Commands}}{{join .Names ", "}}{{ "\t" }}{{.Usage}} -{{end}}{{if .Flags}} -FLAGS: -{{range .Flags}}{{.}} -{{end}}{{end}}` +const Version = "1.1.4" var globalFlags = []cli.Flag{ cli.StringFlag{ @@ -150,8 +134,8 @@ var globalFlags = []cli.Flag{ }, cli.IntFlag{ Name: "gdrive-chunk-size", - Usage: "", - Value: googleapi.DefaultUploadChunkSize / 1024 / 1024, + Usage: "chunk size for gdrive upload in megabytes, must be lower than available memory", + Value: 16, }, cli.IntFlag{ Name: "rate-limit", @@ -236,7 +220,7 @@ func New() *Cmd { app.Description = `Easy file sharing from the command line` app.Version = Version app.Flags = globalFlags - app.CustomAppHelpTemplate = helpTemplate + app.CustomAppHelpTemplate = utils.HelpTemplate app.Commands = []cli.Command{ { Name: "version", diff --git a/server/server.go b/server/server.go index e9534f6..a98b488 100644 --- a/server/server.go +++ b/server/server.go @@ -59,6 +59,50 @@ const _24K = (1 << 3) * 24 // parse request with maximum memory of _5Megabytes const _5M = (1 << 20) * 5 + +type Server struct { + AuthUser string + AuthPass string + + logger *log.Logger + + tlsConfig *tls.Config + + profilerEnabled bool + + locks map[string]*sync.Mutex + + rateLimitRequests int + + storage storage.Storage + + lifetime time.Duration + + forceHTTPs bool + + ipFilterOptions *utils.IPFilterOptions + + VirusTotalKey string + ClamAVDaemonHost string + + tempPath string + + webPath string + proxyPath string + gaKey string + userVoiceKey string + + TLSListenerOnly bool + + ListenerString string + TLSListenerString string + ProfileListenerString string + + Certificate string + + LetsEncryptCache string +} + type OptionFn func(*Server) func ClamavHost(s string) OptionFn { @@ -244,49 +288,6 @@ func FilterOptions(options utils.IPFilterOptions) OptionFn { } } -type Server struct { - AuthUser string - AuthPass string - - logger *log.Logger - - tlsConfig *tls.Config - - profilerEnabled bool - - locks map[string]*sync.Mutex - - rateLimitRequests int - - storage storage.Storage - - lifetime time.Duration - - forceHTTPs bool - - ipFilterOptions *utils.IPFilterOptions - - VirusTotalKey string - ClamAVDaemonHost string - - tempPath string - - webPath string - proxyPath string - gaKey string - userVoiceKey string - - TLSListenerOnly bool - - ListenerString string - TLSListenerString string - ProfileListenerString string - - Certificate string - - LetsEncryptCache string -} - func New(options ...OptionFn) (*Server, error) { s := &Server{ locks: map[string]*sync.Mutex{}, @@ -299,10 +300,6 @@ func New(options ...OptionFn) (*Server, error) { return s, nil } -func init() { - rand.Seed(time.Now().UTC().UnixNano()) -} - func (s *Server) Run() { listening := false @@ -477,3 +474,7 @@ func (s *Server) Run() { func stripPrefix(path string) string { return strings.Replace(path, web.Prefix+"/", "", -1) } + +func init() { + rand.Seed(time.Now().UTC().UnixNano()) +} \ No newline at end of file diff --git a/server/utils/template.go b/server/utils/template.go new file mode 100644 index 0000000..d16aea5 --- /dev/null +++ b/server/utils/template.go @@ -0,0 +1,17 @@ +package utils + +const HelpTemplate = `NAME: +{{.Name}} - {{.Usage}} + +DESCRIPTION: +{{.Description}} + +USAGE: +{{.Name}} {{if .Flags}}[flags] {{end}}command{{if .Flags}}{{end}} [arguments...] + +COMMANDS: +{{range .Commands}}{{join .Names ", "}}{{ "\t" }}{{.Usage}} +{{end}}{{if .Flags}} +FLAGS: +{{range .Flags}}{{.}} +{{end}}{{end}}`