MCPcopy
hub / github.com/istio/istio / Run

Function Run

pkg/ctrlz/ctrlz.go:123–186  ·  view source on GitHub ↗

Run starts up the ControlZ listeners. ControlZ uses the set of standard core topics.

(o *Options, customTopics []fw.Topic)

Source from the content-addressed store, hash-verified

121//
122// ControlZ uses the set of standard core topics.
123func Run(o *Options, customTopics []fw.Topic) (*Server, error) {
124 topicMutex.Lock()
125 allTopics = append(allTopics, coreTopics...)
126 allTopics = append(allTopics, customTopics...)
127 topicMutex.Unlock()
128
129 exec, _ := os.Executable()
130 instance := exec + " - " + getLocalIP()
131
132 funcs := template.FuncMap{
133 "getTopics": getTopics,
134 "normalize": normalize,
135 }
136
137 baseLayout := assets.ParseTemplate(template.New("base"), "templates/layouts/base.html")
138 baseLayout = baseLayout.Funcs(funcs)
139 baseLayout = template.Must(baseLayout.Parse("{{ define \"instance\" }}" + instance + "{{ end }}"))
140 _ = augmentLayout(baseLayout, "templates/modules/header.html")
141 _ = augmentLayout(baseLayout, "templates/modules/sidebar.html")
142 _ = augmentLayout(baseLayout, "templates/modules/last-refresh.html")
143 mainLayout := augmentLayout(template.Must(baseLayout.Clone()), "templates/layouts/main.html")
144
145 router := mux.NewRouter()
146 for _, t := range allTopics {
147 registerTopic(router, mainLayout, t)
148 }
149
150 if o.EnablePprof && o.Address == "localhost" {
151 router.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
152 router.HandleFunc("/debug/pprof/profile", pprof.Profile)
153 router.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
154 router.HandleFunc("/debug/pprof/trace", pprof.Trace)
155 router.PathPrefix("/debug/pprof/").HandlerFunc(pprof.Index)
156 }
157 registerHome(router, mainLayout)
158
159 addr := o.Address
160 if addr == "*" {
161 addr = ""
162 }
163
164 // Canonicalize the address and resolve a dynamic port if necessary
165 listener, err := net.Listen("tcp", fmt.Sprintf("%s:%d", addr, o.Port))
166 if err != nil {
167 log.Errorf("Unable to start ControlZ: %v", err)
168 return nil, err
169 }
170
171 s := &Server{
172 listener: listener,
173 httpServer: http.Server{
174 Addr: listener.Addr().(*net.TCPAddr).String(),
175 ReadTimeout: 10 * time.Second,
176 WriteTimeout: time.Minute, // High timeout to allow profiles to run
177 MaxHeaderBytes: 1 << 20,
178 Handler: router,
179 },
180 }

Callers 3

root.goFile · 0.92
NewServerFunction · 0.92
startAndWaitForServerFunction · 0.70

Calls 12

listenMethod · 0.95
ParseTemplateFunction · 0.92
ErrorfFunction · 0.92
augmentLayoutFunction · 0.85
registerTopicFunction · 0.85
registerHomeFunction · 0.85
ListenMethod · 0.80
getLocalIPFunction · 0.70
NewMethod · 0.65
StringMethod · 0.65
AddMethod · 0.65
CloneMethod · 0.45

Tested by 1

startAndWaitForServerFunction · 0.56