代码拉取完成,页面将自动刷新
package main
import (
"fmt"
"log"
"net/http"
"strings"
)
func handler(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/" && !strings.HasSuffix(r.URL.Path, ".svg") {
http.NotFound(w, r)
return
}
logf("----------------------")
logf(" => handling request: %v", r.URL)
logf("----------------------")
// set up cmdline default for analysis
Analysis.OptsSetup()
// .. and allow overriding by HTTP params
Analysis.OverrideByHTTP(r)
var img string
if img = Analysis.FindCachedImg(); img != "" {
log.Println("serving file:", img)
http.ServeFile(w, r, img)
return
}
// Convert list-style args to []string
if e := Analysis.ProcessListArgs(); e != nil {
http.Error(w, "invalid parameters", http.StatusBadRequest)
return
}
output, err := Analysis.Render()
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
if r.Form.Get("format") == "dot" {
log.Println("writing dot output..")
fmt.Fprint(w, string(output))
return
}
log.Printf("converting dot to %s..\n", *outputFormat)
img, err = dotToImage("", *outputFormat, output)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
err = Analysis.CacheImg(img)
if err != nil {
http.Error(w, "cache img error: "+err.Error(), http.StatusBadRequest)
return
}
log.Println("serving file:", img)
http.ServeFile(w, r, img)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。