MCPcopy
hub / github.com/yusing/godoxy / StartAddRoute

Method StartAddRoute

internal/entrypoint/routes.go:48–97  ·  view source on GitHub ↗
(r types.Route)

Source from the content-addressed store, hash-verified

46}
47
48func (ep *Entrypoint) StartAddRoute(r types.Route) error {
49 if r.ShouldExclude() {
50 ep.excludedRoutes.Add(r)
51 r.Task().OnCancel("remove_route", func() {
52 ep.excludedRoutes.Del(r)
53 })
54 return nil
55 }
56 switch r := r.(type) {
57 case types.HTTPRoute:
58 if err := ep.AddHTTPRoute(r); err != nil {
59 return err
60 }
61 ep.shortLinkMatcher.AddRoute(r.Key())
62 r.Task().OnCancel("remove_route", func() {
63 ep.delHTTPRoute(r)
64 ep.shortLinkMatcher.DelRoute(r.Key())
65 })
66 case types.StreamRoute:
67 if asSNIRoute(r) {
68 if !common.SNIRoutingForTCPRoutes {
69 return fmt.Errorf("route %q listens on the shared HTTPS listener, but TCP SNI routing is disabled", r.Name())
70 }
71 if err := ep.sni.AddRoute(r); err != nil {
72 return err
73 }
74 ep.streamRoutes.Add(r)
75 r.Task().OnCancel("remove_sni_route", func() {
76 ep.sni.DelRoute(r)
77 _ = r.Stream().Close()
78 ep.streamRoutes.Del(r)
79 })
80 return nil
81 }
82
83 err := r.ListenAndServe(r.Task().Context(), nil, nil)
84 if err != nil {
85 return err
86 }
87 ep.streamRoutes.Add(r)
88
89 r.Task().OnCancel("remove_route", func() {
90 r.Stream().Close()
91 ep.streamRoutes.Del(r)
92 })
93 default:
94 return fmt.Errorf("unknown route type: %T", r)
95 }
96 return nil
97}
98
99func getAddr(route types.HTTPRoute) (httpAddr, httpsAddr string) {
100 if port := route.ListenURL().Port(); port == "" || port == "0" {

Callers

nothing calls this directly

Calls 15

AddHTTPRouteMethod · 0.95
delHTTPRouteMethod · 0.95
asSNIRouteFunction · 0.85
ShouldExcludeMethod · 0.65
AddMethod · 0.65
TaskMethod · 0.65
DelMethod · 0.65
AddRouteMethod · 0.65
KeyMethod · 0.65
DelRouteMethod · 0.65
NameMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected