Support https
This commit is contained in:
parent
334c509f8b
commit
c081e37a97
1 changed files with 11 additions and 2 deletions
|
@ -28,12 +28,21 @@ var (
|
||||||
addr = flag.String("addr", "localhost:8080", "http service address")
|
addr = flag.String("addr", "localhost:8080", "http service address")
|
||||||
username = flag.String("user", "", "username")
|
username = flag.String("user", "", "username")
|
||||||
password = flag.String("password", "", "password")
|
password = flag.String("password", "", "password")
|
||||||
|
secure = flag.Bool("s", false, "secure (https/wss)")
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
log.SetFlags(0)
|
log.SetFlags(0)
|
||||||
|
|
||||||
|
secureSuffix := func() string {
|
||||||
|
if *secure {
|
||||||
|
return "s"
|
||||||
|
}
|
||||||
|
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
interrupt := make(chan os.Signal, 1)
|
interrupt := make(chan os.Signal, 1)
|
||||||
signal.Notify(interrupt, os.Interrupt)
|
signal.Notify(interrupt, os.Interrupt)
|
||||||
play := NewPlayer()
|
play := NewPlayer()
|
||||||
|
@ -42,7 +51,7 @@ func main() {
|
||||||
loginForm.Add("username", *username)
|
loginForm.Add("username", *username)
|
||||||
loginForm.Add("password", *password)
|
loginForm.Add("password", *password)
|
||||||
|
|
||||||
loginReq, err := http.NewRequest("POST", "http://"+*addr+"/login", strings.NewReader(loginForm.Encode()))
|
loginReq, err := http.NewRequest("POST", "http"+secureSuffix()+"://"+*addr+"/login", strings.NewReader(loginForm.Encode()))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -72,7 +81,7 @@ func main() {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
u := url.URL{Scheme: "ws", Host: *addr, Path: "/ws"}
|
u := url.URL{Scheme: "ws"+secureSuffix(), Host: *addr, Path: "/ws"}
|
||||||
log.Printf("connecting to %s", u.String())
|
log.Printf("connecting to %s", u.String())
|
||||||
|
|
||||||
dialer := websocket.Dialer{
|
dialer := websocket.Dialer{
|
||||||
|
|
Loading…
Reference in a new issue