/
ugate_ws.go
62 lines (53 loc) · 1.26 KB
/
ugate_ws.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
package bootstrap
import (
"net/http"
"github.com/costinm/ugate/pkg/ugatesvc"
"github.com/gorilla/websocket"
)
func init() {
ugatesvc.InitHooks = append(ugatesvc.InitHooks, func(ug *ugatesvc.UGate) ugatesvc.StartFunc {
w := &ws{ug: ug}
ug.Mux.Handle("/ws/", w)
return nil
})
}
type ws struct {
ug *ugatesvc.UGate
}
// Integrate with Websocket as a server, equvalent with a connect.
// This can also be used for SSH over WS instead of HTTPS over WS.
func (ws *ws) ServeHTTP(w http.ResponseWriter, r *http.Request) {
u := websocket.Upgrader{}
u.Upgrade(w, r, http.Header{})
}
// "golang.org/x/net/websocket" - not supported. Dial only text frames.
//
//func Server() http.Handler {
// wsmsg := &ws.Server{
// Config: ws.Config{},
// Handshake: nil,
// Handler: func(conn *ws.Stream) {
// //h2ctx := auth.AuthContext(conn.Request().Context())
// //websocketStream(conn)
// },
// }
// return wsmsg
// //mux.Handle("/ws", wsmsg)
//}
//
//func Client(dest string) (*ws.Stream, error) {
// wsc, err := ws.NewConfig(dest, dest)
//
// //wsc.Header.Add("Authorization", a.VAPIDToken(dest))
//
// wsc.TlsConfig = &tls.Config{
// InsecureSkipVerify: true,
// }
//
// ws, err := ws.DialConfig(wsc)
// if err != nil {
// return nil, err
// }
//
// return ws, err
//}