cli: Add flag to disable the greeting page (#530)

* feat: add flag to disable the greeting page
Related to #473

* remove `ShowGreeting` from `handler.Config`
This commit is contained in:
Ole-Martin Bratteng 2021-10-23 23:56:37 +02:00 committed by GitHub
parent 968bb1ddcc
commit a8d8b0fea6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 1 deletions

View File

@ -20,6 +20,7 @@ var Flags struct {
MaxSize int64
UploadDir string
Basepath string
ShowGreeting bool
Timeout int64
S3Bucket string
S3ObjectPrefix string
@ -66,6 +67,7 @@ func ParseFlags() {
flag.Int64Var(&Flags.MaxSize, "max-size", 0, "Maximum size of a single upload in bytes")
flag.StringVar(&Flags.UploadDir, "upload-dir", "./data", "Directory to store uploads in")
flag.StringVar(&Flags.Basepath, "base-path", "/files/", "Basepath of the HTTP server")
flag.BoolVar(&Flags.ShowGreeting, "show-greeting", true, "Show the greeting message")
flag.Int64Var(&Flags.Timeout, "timeout", 6*1000, "Read timeout for connections in milliseconds. A zero value means that reads will not timeout")
flag.StringVar(&Flags.S3Bucket, "s3-bucket", "", "Use AWS S3 with this bucket as storage backend (requires the AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY and AWS_REGION environment variables to be set)")
flag.StringVar(&Flags.S3ObjectPrefix, "s3-object-prefix", "", "Prefix for S3 object names")

View File

@ -71,7 +71,9 @@ func Serve() {
http.Handle("/", http.StripPrefix("/", handler))
} else {
// If a custom basepath is defined, we show a greeting at the root path...
http.HandleFunc("/", DisplayGreeting)
if Flags.ShowGreeting {
http.HandleFunc("/", DisplayGreeting)
}
// ... and register a route with and without the trailing slash, so we can
// handle uploads for /files/ and /files, for example.