mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-21 07:51:28 +02:00
fix(stream): nil panic for excluded routes
This commit is contained in:
@@ -28,13 +28,7 @@ type StreamRoute struct {
|
|||||||
|
|
||||||
func NewStreamRoute(base *Route) (types.Route, gperr.Error) {
|
func NewStreamRoute(base *Route) (types.Route, gperr.Error) {
|
||||||
// TODO: support non-coherent scheme
|
// TODO: support non-coherent scheme
|
||||||
return &StreamRoute{
|
return &StreamRoute{Route: base}, nil
|
||||||
Route: base,
|
|
||||||
l: log.With().
|
|
||||||
Str("type", base.LisURL.Scheme).
|
|
||||||
Str("name", base.Name()).
|
|
||||||
Logger(),
|
|
||||||
}, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *StreamRoute) Stream() nettypes.Stream {
|
func (r *StreamRoute) Stream() nettypes.Stream {
|
||||||
@@ -43,6 +37,10 @@ func (r *StreamRoute) Stream() nettypes.Stream {
|
|||||||
|
|
||||||
// Start implements task.TaskStarter.
|
// Start implements task.TaskStarter.
|
||||||
func (r *StreamRoute) Start(parent task.Parent) gperr.Error {
|
func (r *StreamRoute) Start(parent task.Parent) gperr.Error {
|
||||||
|
if r.LisURL == nil {
|
||||||
|
return gperr.Errorf("listen URL is not set")
|
||||||
|
}
|
||||||
|
|
||||||
stream, err := r.initStream()
|
stream, err := r.initStream()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return gperr.Wrap(err)
|
return gperr.Wrap(err)
|
||||||
@@ -71,7 +69,11 @@ func (r *StreamRoute) Start(parent task.Parent) gperr.Error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
r.ListenAndServe(r.task.Context(), nil, nil)
|
r.ListenAndServe(r.task.Context(), nil, nil)
|
||||||
r.l = r.l.With().Stringer("rurl", r.ProxyURL).Stringer("laddr", r.LocalAddr()).Logger()
|
r.l = log.With().
|
||||||
|
Str("type", r.LisURL.Scheme).
|
||||||
|
Str("name", r.Name()).
|
||||||
|
Stringer("rurl", r.ProxyURL).
|
||||||
|
Stringer("laddr", r.LocalAddr()).Logger()
|
||||||
r.l.Info().Msg("stream started")
|
r.l.Info().Msg("stream started")
|
||||||
|
|
||||||
r.task.OnCancel("close_stream", func() {
|
r.task.OnCancel("close_stream", func() {
|
||||||
|
|||||||
Reference in New Issue
Block a user