-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathmain.go
61 lines (54 loc) · 1.51 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
package main
import (
"flag"
"log"
"net/http"
"os"
"path/filepath"
"runtime"
"time"
"github.com/facebookgo/httpcontrol"
"github.com/mjibson/moggio/server"
// codecs
_ "github.com/mjibson/moggio/codec/flac"
_ "github.com/mjibson/moggio/codec/gme"
_ "github.com/mjibson/moggio/codec/mpa"
_ "github.com/mjibson/moggio/codec/nsf"
_ "github.com/mjibson/moggio/codec/rar"
_ "github.com/mjibson/moggio/codec/vorbis"
_ "github.com/mjibson/moggio/codec/wav"
// protocols
_ "github.com/mjibson/moggio/protocol/file"
_ "github.com/mjibson/moggio/protocol/stream"
)
var (
flagAddr = flag.String("addr", ":6601", "listen address")
flagDev = flag.Bool("dev", false, "enable dev mode")
stateFile = flag.String("state", "", "specify non-default statefile location")
)
func main() {
flag.Parse()
http.DefaultClient = &http.Client{
Transport: &httpcontrol.Transport{
ResponseHeaderTimeout: time.Second * 3,
MaxTries: 3,
RetryAfterTimeout: true,
},
}
if *stateFile == "" {
switch {
case *flagDev:
*stateFile = "moggio.state"
case runtime.GOOS == "windows":
dir := filepath.Join(os.Getenv("APPDATA"), "moggio")
if err := os.MkdirAll(dir, 0600); err != nil {
log.Fatal(err)
}
*stateFile = filepath.Join(dir, "moggio.state")
default:
*stateFile = filepath.Join(os.Getenv("HOME"), ".moggio.state")
}
}
log.Fatal(server.ListenAndServe(*stateFile, *flagAddr, *flagDev))
}
//go:generate browserify -t [ reactify --es6 ] server/static/src/nav.js -o server/static/js/moggio.js