This repository has been archived by the owner on Jun 21, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.go
65 lines (58 loc) · 1.75 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package main
import (
"flag"
"fmt"
"io/ioutil"
"log"
"net/http"
"net/http/fcgi"
"os"
)
var (
noupload = false
user string
password string
auth string
dir = "."
mode = "http"
index string
// VERSION application version
VERSION string
)
func main() {
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "Usage of %s:\n", os.Args[0])
flag.PrintDefaults()
}
address := flag.String("addr", "0.0.0.0:4000", "listen on this address")
flag.BoolVar(&noupload, "noupload", noupload, "enable or disable uploads")
flag.StringVar(&user, "user", user, "user for HTTP Basic authentication (-auth needs to be set)")
flag.StringVar(&password, "password", password, "password for HTTP Basic authentication (-auth needs to be set)")
flag.StringVar(&auth, "auth", auth, "comma-separated list of what will be protected by HTTP Basic authentication (index,download,upload)")
flag.StringVar(&dir, "dir", dir, "directory for storing and serving files")
flag.StringVar(&mode, "mode", mode, "run either standalone (http) or as FCGI application (fcgi)")
flag.StringVar(&index, "index", index, "serve this file if it exists in the current directory instead of a listing")
verbose := flag.Bool("v", false, "verbose output (no output at all by default)")
version := flag.Bool("version", false, "show version and exit")
flag.Parse()
if *version {
fmt.Println(VERSION)
return
}
log.SetOutput(ioutil.Discard)
if *verbose {
log.SetOutput(os.Stdout)
flag.VisitAll(func(f *flag.Flag) {
log.Printf("SETTINGS: %s = %s", f.Name, f.Value)
})
}
http.HandleFunc("/", handler)
switch mode {
case "http":
log.Fatal(http.ListenAndServe(*address, nil))
case "fcgi":
log.Fatal(fcgi.Serve(nil, nil))
default:
log.Fatalf("Unknown mode '%s'!", mode)
}
}