~pkal/survey

1951624bfcf1de91eebd4c63dc3583be6792d3f0 — Philip K 1 year, 7 months ago 875d359
Replace all panic calls with log.Fatal et al.
1 files changed, 13 insertions(+), 13 deletions(-)

M survey.go
M survey.go => survey.go +13 -13
@@ 4,16 4,16 @@ import (
	"bufio"
	"bytes"
	"database/sql"
	"flag"
	"fmt"
	"html/template"
	"io"
	"io/ioutil"
	"log"
	"log/syslog"
	"net/http"
	"os"
	"strconv"
	"flag"
	"io/ioutil"
	"log/syslog"

	"github.com/dchest/captcha"
	_ "github.com/mattn/go-sqlite3"


@@ 290,7 290,7 @@ func submit(w http.ResponseWriter, r *http.Request) {
				_, err = stmt.Exec(i, nil, value)
			}
		default:
			panic("invalid question type")
			l.Fatalf("Invalid question type '%v'", q.Type)
		}

		if err != nil {


@@ 387,7 387,7 @@ func parseSummary(in io.Reader) *Survey {
		}
	}
	if scan.Err() != nil {
		panic(scan.Err())
		l.Fatal(scan.Err())
	}

	return &s


@@ 418,7 418,7 @@ func main() {
	var buf bytes.Buffer
	T, err = template.New("page").Parse(page)
	if err != nil {
		panic(err)
		l.Fatal(err)
	}
	err = T.Execute(&buf, survey)
	rawPage = buf.Bytes()


@@ 426,13 426,13 @@ func main() {

	T, err = template.New("captcha").Parse(captchat)
	if err != nil {
		panic(err)
		l.Fatal(err)
	}
	l.Printf("Loaded captcha template.")

	db, err = sql.Open("sqlite3", "./survey.db?mode=rwc&_journal=wal")
	if err != nil {
		panic(err)
		l.Fatal(err)
	}
	defer db.Close()
	l.Print("Opened database connection.")


@@ 443,7 443,7 @@ id INTEGER PRIMARY KEY,
date INTEGER,
contact TEXT);`)
	if err != nil {
		panic(err)
		l.Fatal(err)
	}

	_, err = db.Exec(`


@@ 454,21 454,21 @@ answer INTEGER,
text TEXT,
FOREIGN KEY(response) REFERENCES response(id));`)
	if err != nil {
		panic(err)
		l.Fatal(err)
	}

	insertResponse, err = db.Prepare(`
INSERT INTO response (date, contact)
VALUES (strftime('%s', 'now'), ?);`)
	if err != nil {
		panic(err)
		l.Fatal(err)
	}

	insertAnswer, err = db.Prepare(`
INSERT INTO answer (response, question, answer, text)
VALUES ((SELECT MAX(id) FROM response), ?, ?, ?);`)
	if err != nil {
		panic(err)
		l.Fatal(err)
	}

	l.Print("Prepared database connection.")


@@ 483,5 483,5 @@ VALUES ((SELECT MAX(id) FROM response), ?, ?, ?);`)
	}

	l.Printf("Starting server on %s.", listen)
	l.Panic(http.ListenAndServe(listen, nil))
	l.Fatal(http.ListenAndServe(listen, nil))
}