MCPcopy Index your code
hub / github.com/cloudflare/cloudflared / rootHandler

Function rootHandler

hello/hello.go:232–255  ·  view source on GitHub ↗
(serverName string)

Source from the content-addressed store, hash-verified

230}
231
232func rootHandler(serverName string) http.HandlerFunc {
233 responseTemplate := template.Must(template.New("index").Parse(indexTemplate))
234 return func(w http.ResponseWriter, r *http.Request) {
235 var buffer bytes.Buffer
236 var body string
237 rawBody, err := io.ReadAll(r.Body)
238 if err == nil {
239 body = string(rawBody)
240 } else {
241 body = ""
242 }
243 err = responseTemplate.Execute(&buffer, &templateData{
244 ServerName: serverName,
245 Request: r,
246 Body: body,
247 })
248 if err != nil {
249 w.WriteHeader(http.StatusInternalServerError)
250 _, _ = fmt.Fprintf(w, "error: %v", err)
251 } else {
252 _, _ = buffer.WriteTo(w)
253 }
254 }
255}

Callers 1

StartHelloWorldServerFunction · 0.85

Calls 2

ExecuteMethod · 0.80
WriteHeaderMethod · 0.45

Tested by

no test coverage detected