]> de.git.xonotic.org Git - xonotic/xonstat.git/blob - xonstat/util/xs_submit.go
Two new utilities written in Go.
[xonotic/xonstat.git] / xonstat / util / xs_submit.go
1 package main
2
3 import "bytes"
4 import "flag"
5 import "fmt"
6 import "io/ioutil"
7 import "net/http"
8 import "os"
9
10 /* xs_submit takes a file containing a single XonStat request and submits it
11    to the server URL specified */
12 func main() {
13   var fn = flag.String("file", "xonstat.log", "Logfile from XonStat")
14   var url = flag.String("url", "http://localhost:6543/stats/submit", "XonStat submission URL")
15   flag.Parse()
16
17   body, err := ioutil.ReadFile(*fn)
18   if err != nil {
19     fmt.Printf("Issue opening file %s\n", *fn)
20     os.Exit(1)
21   }
22   contentlength := int64(len(body))
23
24   r := bytes.NewReader(body)
25
26   req, _ := http.NewRequest("POST", *url, r)
27   req.ContentLength = contentlength
28   res, _ := http.DefaultClient.Do(req)
29   defer res.Body.Close()
30
31   fmt.Printf("%s: %s\n", *fn, res.Status)
32 }