minor reorg

This commit is contained in:
Özgür Kesim 2017-11-22 19:28:32 -08:00
parent 1de19c6376
commit b333ed97cf
2 changed files with 9 additions and 5 deletions

12
main.go
View File

@ -23,6 +23,7 @@ var (
cert = flag.String("cert", "cert.pem", "certitifate") cert = flag.String("cert", "cert.pem", "certitifate")
key = flag.String("key", "key.pem", "key") key = flag.String("key", "key.pem", "key")
savedir = flag.String("d", "saved", "direcotry to save the pics.") savedir = flag.String("d", "saved", "direcotry to save the pics.")
tools = []Tool{}
) )
type Tool struct { type Tool struct {
@ -36,14 +37,16 @@ type Tool struct {
BgColor string BgColor string
} }
var tools = []Tool{}
func (t Tool) execute(in io.Reader, w http.ResponseWriter) { func (t Tool) execute(in io.Reader, w http.ResponseWriter) {
var cmd = exec.Command(t.Cmd, t.Args...) // Call to dot with SVG-output in safe-mode var (
cmd = exec.Command(t.Cmd, t.Args...)
err, buf = &bytes.Buffer{}, &bytes.Buffer{}
)
cmd.Stdin = in cmd.Stdin = in
err, buf := &bytes.Buffer{}, &bytes.Buffer{}
cmd.Stderr = err cmd.Stderr = err
cmd.Stdout = buf cmd.Stdout = buf
if e := cmd.Run(); e == nil { if e := cmd.Run(); e == nil {
io.Copy(w, buf) io.Copy(w, buf)
} else { } else {
@ -135,6 +138,7 @@ func (t Tool) index() func(http.ResponseWriter, *http.Request) {
} }
func main() { func main() {
var tools = []Tool{}
flag.Parse() flag.Parse()

View File

@ -2,7 +2,7 @@
{ {
"Name": "dot", "Name": "dot",
"Cmd": "dot", "Cmd": "dot",
"Args": ["-Tsvg", "-v"], "Args": ["-Tsvg"],
"Suffix": ".dot", "Suffix": ".dot",
"Description": "Graphviz, dot", "Description": "Graphviz, dot",
"BgColor": "CadetBlue", "BgColor": "CadetBlue",