mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2025-04-28 22:25:07 +03:00
Fix lint issues, rename /h
to /health
, set HTTP server base context, formatting tweaks
This commit is contained in:
parent
6c02e30bc9
commit
1521e1e299
2 changed files with 10 additions and 17 deletions
|
@ -48,20 +48,19 @@ func (l *linkWSListener) Close() error {
|
||||||
if err := l.httpServer.Shutdown(l.ctx); err != nil {
|
if err := l.httpServer.Shutdown(l.ctx); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return l.listener.Close()
|
return l.listener.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *wsServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
func (s *wsServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
if r.URL.Path == "/h" {
|
if r.URL.Path == "/health" {
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
w.Write([]byte("OK"))
|
_, _ = w.Write([]byte("OK"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c, err := websocket.Accept(w, r, &websocket.AcceptOptions{
|
c, err := websocket.Accept(w, r, &websocket.AcceptOptions{
|
||||||
Subprotocols: []string{"ygg-ws"},
|
Subprotocols: []string{"ygg-ws"},
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -71,11 +70,8 @@ func (s *wsServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
netconn := websocket.NetConn(s.ctx, c, websocket.MessageBinary)
|
s.ch <- &linkWSConn{
|
||||||
|
Conn: websocket.NetConn(s.ctx, c, websocket.MessageBinary),
|
||||||
ch := s.ch
|
|
||||||
ch <- &linkWSConn{
|
|
||||||
Conn: netconn,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,7 +79,6 @@ func (l *links) newLinkWS() *linkWS {
|
||||||
lt := &linkWS{
|
lt := &linkWS{
|
||||||
links: l,
|
links: l,
|
||||||
}
|
}
|
||||||
|
|
||||||
return lt
|
return lt
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,9 +89,8 @@ func (l *linkWS) dial(ctx context.Context, url *url.URL, info linkInfo, options
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
netconn := websocket.NetConn(ctx, wsconn, websocket.MessageBinary)
|
|
||||||
return &linkWSConn{
|
return &linkWSConn{
|
||||||
Conn: netconn,
|
Conn: websocket.NetConn(ctx, wsconn, websocket.MessageBinary),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,6 +107,7 @@ func (l *linkWS) listen(ctx context.Context, url *url.URL, _ string) (net.Listen
|
||||||
ch: ch,
|
ch: ch,
|
||||||
ctx: ctx,
|
ctx: ctx,
|
||||||
},
|
},
|
||||||
|
BaseContext: func(_ net.Listener) context.Context { return ctx },
|
||||||
ReadTimeout: time.Second * 10,
|
ReadTimeout: time.Second * 10,
|
||||||
WriteTimeout: time.Second * 10,
|
WriteTimeout: time.Second * 10,
|
||||||
}
|
}
|
||||||
|
@ -123,6 +118,6 @@ func (l *linkWS) listen(ctx context.Context, url *url.URL, _ string) (net.Listen
|
||||||
httpServer: httpServer,
|
httpServer: httpServer,
|
||||||
listener: nl,
|
listener: nl,
|
||||||
}
|
}
|
||||||
go lwl.httpServer.Serve(nl)
|
go lwl.httpServer.Serve(nl) // nolint:errcheck
|
||||||
return lwl, nil
|
return lwl, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,6 @@ func (l *links) newLinkWSS() *linkWSS {
|
||||||
lwss := &linkWSS{
|
lwss := &linkWSS{
|
||||||
links: l,
|
links: l,
|
||||||
}
|
}
|
||||||
|
|
||||||
return lwss
|
return lwss
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,9 +33,8 @@ func (l *linkWSS) dial(ctx context.Context, url *url.URL, info linkInfo, options
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
netconn := websocket.NetConn(ctx, wsconn, websocket.MessageBinary)
|
|
||||||
return &linkWSSConn{
|
return &linkWSSConn{
|
||||||
Conn: netconn,
|
Conn: websocket.NetConn(ctx, wsconn, websocket.MessageBinary),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue