Cleanup
This commit is contained in:
parent
83d709398c
commit
3ea94d85aa
59
server.go
59
server.go
@ -42,7 +42,12 @@ import (
|
|||||||
_ "github.com/mattn/go-sqlite3"
|
_ "github.com/mattn/go-sqlite3"
|
||||||
)
|
)
|
||||||
|
|
||||||
var db *sql.DB
|
var (
|
||||||
|
staticDir = flag.String("static", "static", "static files path")
|
||||||
|
portNum = flag.Int("port", 8080, "port to serve content on")
|
||||||
|
dataSrc = flag.String("db", "build/data/db.sqlite3", "database path")
|
||||||
|
profile = flag.String("profile", "", "write cpu profile to file")
|
||||||
|
)
|
||||||
|
|
||||||
func prepareColumn(steps int, minScore float64, allEntries, matchedEntries []record, features map[string]float64, modes map[string]modeType, name string, col *column, wg *sync.WaitGroup) {
|
func prepareColumn(steps int, minScore float64, allEntries, matchedEntries []record, features map[string]float64, modes map[string]modeType, name string, col *column, wg *sync.WaitGroup) {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
@ -84,6 +89,13 @@ func prepareColumn(steps int, minScore float64, allEntries, matchedEntries []rec
|
|||||||
func handleExecuteQuery(rw http.ResponseWriter, req *http.Request) {
|
func handleExecuteQuery(rw http.ResponseWriter, req *http.Request) {
|
||||||
startTime := time.Now()
|
startTime := time.Now()
|
||||||
|
|
||||||
|
db, err := sql.Open("sqlite3", *dataSrc)
|
||||||
|
if err != nil {
|
||||||
|
http.Error(rw, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer db.Close()
|
||||||
|
|
||||||
var (
|
var (
|
||||||
request struct {
|
request struct {
|
||||||
Features map[string]float64 `json:"features"`
|
Features map[string]float64 `json:"features"`
|
||||||
@ -171,6 +183,13 @@ func handleExecuteQuery(rw http.ResponseWriter, req *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func handleGetCategories(rw http.ResponseWriter, req *http.Request) {
|
func handleGetCategories(rw http.ResponseWriter, req *http.Request) {
|
||||||
|
db, err := sql.Open("sqlite3", *dataSrc)
|
||||||
|
if err != nil {
|
||||||
|
http.Error(rw, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer db.Close()
|
||||||
|
|
||||||
categoryRows, err := db.Query("SELECT description, id FROM categories")
|
categoryRows, err := db.Query("SELECT description, id FROM categories")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(rw, err.Error(), http.StatusInternalServerError)
|
http.Error(rw, err.Error(), http.StatusInternalServerError)
|
||||||
@ -214,6 +233,13 @@ func handleGetCategories(rw http.ResponseWriter, req *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func handleAddCategory(rw http.ResponseWriter, req *http.Request) {
|
func handleAddCategory(rw http.ResponseWriter, req *http.Request) {
|
||||||
|
db, err := sql.Open("sqlite3", *dataSrc)
|
||||||
|
if err != nil {
|
||||||
|
http.Error(rw, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer db.Close()
|
||||||
|
|
||||||
var (
|
var (
|
||||||
request struct {
|
request struct {
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
@ -267,6 +293,13 @@ func handleAddCategory(rw http.ResponseWriter, req *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func handleRemoveCategory(rw http.ResponseWriter, req *http.Request) {
|
func handleRemoveCategory(rw http.ResponseWriter, req *http.Request) {
|
||||||
|
db, err := sql.Open("sqlite3", *dataSrc)
|
||||||
|
if err != nil {
|
||||||
|
http.Error(rw, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer db.Close()
|
||||||
|
|
||||||
var (
|
var (
|
||||||
request struct {
|
request struct {
|
||||||
Id int `json:"id"`
|
Id int `json:"id"`
|
||||||
@ -297,6 +330,13 @@ func handleRemoveCategory(rw http.ResponseWriter, req *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func handleAccessReview(rw http.ResponseWriter, req *http.Request) {
|
func handleAccessReview(rw http.ResponseWriter, req *http.Request) {
|
||||||
|
db, err := sql.Open("sqlite3", *dataSrc)
|
||||||
|
if err != nil {
|
||||||
|
http.Error(rw, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer db.Close()
|
||||||
|
|
||||||
var request struct {
|
var request struct {
|
||||||
Id int `json:"id"`
|
Id int `json:"id"`
|
||||||
Profile map[string]float64 `json:"profile"`
|
Profile map[string]float64 `json:"profile"`
|
||||||
@ -357,6 +397,13 @@ func handleAccessReview(rw http.ResponseWriter, req *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func handleClearHistory(rw http.ResponseWriter, req *http.Request) {
|
func handleClearHistory(rw http.ResponseWriter, req *http.Request) {
|
||||||
|
db, err := sql.Open("sqlite3", *dataSrc)
|
||||||
|
if err != nil {
|
||||||
|
http.Error(rw, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer db.Close()
|
||||||
|
|
||||||
if _, err := db.Exec("DELETE FROM historyGroups"); err != nil {
|
if _, err := db.Exec("DELETE FROM historyGroups"); err != nil {
|
||||||
http.Error(rw, err.Error(), http.StatusInternalServerError)
|
http.Error(rw, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
@ -372,18 +419,8 @@ func handleClearHistory(rw http.ResponseWriter, req *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
staticDir := flag.String("static", "static", "static files path")
|
|
||||||
portNum := flag.Int("port", 8080, "port to serve content on")
|
|
||||||
dataSrc := flag.String("db", "build/data/db.sqlite3", "database path")
|
|
||||||
profile := flag.String("profile", "", "write cpu profile to file")
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
var err error
|
|
||||||
if db, err = sql.Open("sqlite3", *dataSrc); err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
defer db.Close()
|
|
||||||
|
|
||||||
if *profile != "" {
|
if *profile != "" {
|
||||||
f, err := os.Create(*profile)
|
f, err := os.Create(*profile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user