Add Hosting Support

This commit is contained in:
M. Fatih MAR 2019-01-06 20:09:32 +00:00
parent 3cb33d48d3
commit b1804f5412

View file

@ -1,15 +1,12 @@
package main package main
import ( import (
"bytes" "net/http"
"log"
"os"
"github.com/wcharczuk/go-chart" chart "github.com/wcharczuk/go-chart"
) )
func main() { func drawChart(res http.ResponseWriter, req *http.Request) {
var b float64 var b float64
b = 1000 b = 1000
@ -51,18 +48,11 @@ func main() {
}, },
} }
buffer := bytes.NewBuffer([]byte{}) res.Header().Set("Content-Type", "image/png")
err := graph.Render(chart.PNG, buffer) graph.Render(chart.PNG, res)
if err != nil { }
log.Fatal(err)
} func main() {
http.HandleFunc("/", drawChart)
fo, err := os.Create("output.png") http.ListenAndServe(":8080", nil)
if err != nil {
panic(err)
}
if _, err := fo.Write(buffer.Bytes()); err != nil {
panic(err)
}
} }