Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rageshake: Abide by Go standards #3149

Merged
merged 1 commit into from
Feb 6, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions scripts/rageshake.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"log"
"net/http"
"os"
"path/filepath"
"strconv"
"time"
)
Expand All @@ -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
Expand All @@ -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
Expand Down