-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.go
45 lines (37 loc) · 900 Bytes
/
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
package main
import (
"flag"
"fmt"
"log"
"net/http"
"os"
"strings"
"github.com/akokshar/storage/server"
)
const (
paramBasedirName = "basedir"
defaultBasedir = "/Users/akoksharov/Downloads/Store"
paramPortName = "port"
defaultPort = "8080"
)
func main() {
var basedir string
var port string
flag.StringVar(&basedir, paramBasedirName, "", "The directory with files")
flag.StringVar(&port, paramPortName, "", "Listen port")
flag.Parse()
if basedir == "" {
basedir, _ = os.LookupEnv(strings.ToUpper(paramBasedirName))
if basedir == "" {
basedir = defaultBasedir
}
}
if port == "" {
port, _ = os.LookupEnv(strings.ToUpper(paramPortName))
if port == "" {
port = defaultPort
}
}
log.Printf("Storage is about to serve `%s` on port `%s`\n", basedir, port)
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%s", port), server.CreateApplication(basedir)))
}