Merge pull request #3149 from vector-im/kegan/go-stds

rageshake: Abide by Go standards
pull/3162/head
Kegsay 2017-02-06 15:40:58 +00:00 committed by GitHub
commit 1f0b4853be
1 changed files with 7 additions and 5 deletions

View File

@ -13,6 +13,7 @@ import (
"log"
"net/http"
"os"
"path/filepath"
"strconv"
"time"
)
@ -36,9 +37,10 @@ func respond(code int, w http.ResponseWriter) {
w.Write([]byte("{}"))
}
func gzipAndSave(data []byte, filepath string) error {
filepath = "bugs/" + filepath
if _, err := os.Stat(filepath); err == nil {
func gzipAndSave(data []byte, fpath string) error {
fpath = filepath.Join("bugs", fpath)
if _, err := os.Stat(fpath); err == nil {
return fmt.Errorf("file already exists") // the user can just retry
}
var b bytes.Buffer
@ -52,14 +54,14 @@ func gzipAndSave(data []byte, filepath string) error {
if err := gz.Close(); err != nil {
return err
}
if err := ioutil.WriteFile(filepath, b.Bytes(), 0644); err != nil {
if err := ioutil.WriteFile(fpath, b.Bytes(), 0644); err != nil {
return err
}
return nil
}
func main() {
http.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
http.HandleFunc("/api/submit", func(w http.ResponseWriter, req *http.Request) {
if req.Method != "POST" && req.Method != "OPTIONS" {
respond(405, w)
return