2 Star 0 Fork 0

glaye/go-callvis

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
handler.go 1.37 KB
一键复制 编辑 原始数据 按行查看 历史
Georg Gentzen 提交于 2020-12-29 22:45 . File position (#67)
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)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/glaye/go-callvis.git
git@gitee.com:glaye/go-callvis.git
glaye
go-callvis
go-callvis
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385