-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathconfig.go
74 lines (62 loc) · 1.93 KB
/
config.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
66
67
68
69
70
71
72
73
74
package main // github.com/gitinsky/vnc-go-web
import (
"flag"
"fmt"
"os"
"strings"
)
const (
authCookieName = "vnc-go-web"
)
type Config struct {
// http server specific parameters
listen *string
ssl *bool
root *string
passwd *string
vnc *string
auth *string
resolv *string
authTTL *float64
baseuri *string
// VNC server specific parameters
vnc_port *int
vnc_true_color *bool
vnc_local_cursor *bool
vnc_shared *bool
vnc_view_only *bool
}
var cfg = Config{
listen: flag.String("listen", ":8080", "Address to HTTP(S) listen. [ADDR]:PORT"),
ssl: flag.Bool("ssl", false, "Use SSL"),
root: flag.String("root", "./", "Document root for static pages"),
passwd: flag.String("passwd", "", "Password file name"),
vnc: flag.String("vnc", "", "Address of the VNC server to connect"),
auth: flag.String("auth", "http://127.0.0.1/auth?", "External authentication URL"),
resolv: flag.String("resolv", "http://127.0.0.1/resolv?", "External ID to IP resolving URL"),
authTTL: flag.Float64("authTTL", 10, "Authentication token TTL in seconds"),
baseuri: flag.String("baseuri", "", "Base URI"),
vnc_port: flag.Int("vnc_port", 5900, "VNC port to connect"),
vnc_true_color: flag.Bool("vnc_true_color", false, "true_color noVNC param"),
vnc_local_cursor: flag.Bool("vnc_local_cursor", true, "cursor noVNC param"),
vnc_shared: flag.Bool("vnc_shared", true, "shared noVNC param"),
vnc_view_only: flag.Bool("vnc_view_only", false, "view_only noVNC param"),
}
func (cfg *Config) Parse() {
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "Usage:\n")
flag.PrintDefaults()
}
flag.Parse()
str := strings.Trim(*cfg.baseuri, " \t\r\n/")
str = "/" + str + ternary(len(str) > 0, "/", "").(string)
cfg.baseuri = &str
}
type strList []string
func (s *strList) String() string {
return fmt.Sprintf("%s", *s)
}
func (s *strList) Set(v string) error {
*s = append(*s, v)
return nil
}