Cleanup
This commit is contained in:
parent
1ac7434c45
commit
6debf10a57
29
server.go
29
server.go
@ -25,13 +25,13 @@ package main
|
||||
import (
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"fmt"
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
)
|
||||
|
||||
var db *sql.DB
|
||||
@ -258,21 +258,14 @@ func clearHistory(rw http.ResponseWriter, req *http.Request) {
|
||||
fmt.Fprint(rw, "History tables cleared")
|
||||
}
|
||||
|
||||
func staticPath() (string, error) {
|
||||
if len(os.Args) > 1 {
|
||||
return os.Args[1], nil
|
||||
}
|
||||
|
||||
return filepath.Abs(filepath.Join(filepath.Dir(os.Args[0]), "static"))
|
||||
}
|
||||
|
||||
func main() {
|
||||
dir, err := staticPath()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
staticDir := flag.String("static", "static", "path to static files")
|
||||
portNum := flag.Int("port", 8080, "port to serve content on")
|
||||
dataSrc := flag.String("data", "hscd@/hscd", "data source for database")
|
||||
flag.Parse()
|
||||
|
||||
db, err = sql.Open("mysql", "hscd@/hscd")
|
||||
var err error
|
||||
db, err = sql.Open("mysql", *dataSrc)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
@ -284,7 +277,7 @@ func main() {
|
||||
http.HandleFunc("/forget", removeCategory)
|
||||
http.HandleFunc("/access", accessReview)
|
||||
http.HandleFunc("/clear", clearHistory)
|
||||
http.Handle("/", http.FileServer(http.Dir(dir)))
|
||||
http.Handle("/", http.FileServer(http.Dir(*staticDir)))
|
||||
|
||||
log.Fatal(http.ListenAndServe(":8080", nil))
|
||||
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", *portNum), nil))
|
||||
}
|
||||
|
24
types.go
24
types.go
@ -140,23 +140,23 @@ type recordSorter struct {
|
||||
key string
|
||||
}
|
||||
|
||||
func (sorter recordSorter) sort() {
|
||||
if sorter.ascending {
|
||||
sort.Sort(sorter)
|
||||
func (s recordSorter) sort() {
|
||||
if s.ascending {
|
||||
sort.Sort(s)
|
||||
} else {
|
||||
sort.Sort(sort.Reverse(sorter))
|
||||
sort.Sort(sort.Reverse(s))
|
||||
}
|
||||
}
|
||||
|
||||
func (sorter recordSorter) Len() int {
|
||||
return len(sorter.entries)
|
||||
func (s recordSorter) Len() int {
|
||||
return len(s.entries)
|
||||
}
|
||||
|
||||
func (sorter recordSorter) Less(i, j int) bool {
|
||||
entry1 := sorter.entries[i]
|
||||
entry2 := sorter.entries[j]
|
||||
func (s recordSorter) Less(i, j int) bool {
|
||||
entry1 := s.entries[i]
|
||||
entry2 := s.entries[j]
|
||||
|
||||
switch sorter.key {
|
||||
switch s.key {
|
||||
case "accessCount":
|
||||
return entry1.accessCount < entry2.accessCount
|
||||
case "closestStn":
|
||||
@ -174,6 +174,6 @@ func (sorter recordSorter) Less(i, j int) bool {
|
||||
}
|
||||
}
|
||||
|
||||
func (sorter recordSorter) Swap(i, j int) {
|
||||
sorter.entries[i], sorter.entries[j] = sorter.entries[j], sorter.entries[i]
|
||||
func (s recordSorter) Swap(i, j int) {
|
||||
s.entries[i], s.entries[j] = s.entries[j], s.entries[i]
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user