-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
58 lines (52 loc) · 1.91 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
package main
import (
"github.com/chrisvdg/gotiny/server"
log "github.com/sirupsen/logrus"
"github.com/spf13/pflag"
)
func main() {
listAddr := pflag.StringP("listenaddr", "l", ":8080", "http listen address")
tlsListAddr := pflag.StringP("tlsaddr", "t", "8443", "https listen address")
tlsKey := pflag.StringP("tlskey", "k", "", "TLS private key file path")
tlsCert := pflag.StringP("tlscert", "c", "", "TLS certificate file path")
readToken := pflag.StringP("readtoken", "r", "", "Read authorization token")
writeToken := pflag.StringP("writetoken", "w", "", "Write authorization token")
allowPublicCreate := pflag.BoolP("allowpubliccreate", "p", false, "Allows creation of generated tiny URLs without authorization when write token is set")
idLen := pflag.IntP("idlen", "i", 5, "Length of generated tiny URL IDs")
prettyJSON := pflag.BoolP("prettyjson", "j", false, "API outputs more readable JSON")
fileBackendPath := pflag.StringP("filebackend", "f", "", "File to store file backend data")
verbose := pflag.BoolP("verbose", "v", false, "Verbose output")
pflag.Parse()
c := &server.Config{
ListenAddr: *listAddr,
TLSListenAddr: *tlsListAddr,
TLS: &server.TLSConfig{
KeyFile: *tlsKey,
CertFile: *tlsCert,
},
ReadAuthToken: *readToken,
WriteAuthToken: *writeToken,
AllowPublicCreateGenerated: *allowPublicCreate,
GeneratedIDLen: *idLen,
PrettyJSON: *prettyJSON,
FileBackendPath: *fileBackendPath,
Verbose: *verbose,
}
if c.Verbose {
log.SetLevel(log.DebugLevel)
} else {
log.SetLevel(log.InfoLevel)
}
log.SetFormatter(&log.TextFormatter{
FullTimestamp: true,
TimestampFormat: "15:04:05 02/01/2006",
})
s, err := server.New(c)
if err != nil {
log.Fatalf("Failed to init server: %s", err)
}
err = s.ListenAndServeFileBackedAPI()
if err != nil {
log.Fatalf("Failed to run server: %s", err)
}
}