Cleanup
This commit is contained in:
parent
1ac7434c45
commit
6debf10a57
29
server.go
29
server.go
@ -25,13 +25,13 @@ package main
|
|||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
_ "github.com/go-sql-driver/mysql"
|
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
_ "github.com/go-sql-driver/mysql"
|
||||||
)
|
)
|
||||||
|
|
||||||
var db *sql.DB
|
var db *sql.DB
|
||||||
@ -258,21 +258,14 @@ func clearHistory(rw http.ResponseWriter, req *http.Request) {
|
|||||||
fmt.Fprint(rw, "History tables cleared")
|
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() {
|
func main() {
|
||||||
dir, err := staticPath()
|
staticDir := flag.String("static", "static", "path to static files")
|
||||||
if err != nil {
|
portNum := flag.Int("port", 8080, "port to serve content on")
|
||||||
log.Fatal(err)
|
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 {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -284,7 +277,7 @@ func main() {
|
|||||||
http.HandleFunc("/forget", removeCategory)
|
http.HandleFunc("/forget", removeCategory)
|
||||||
http.HandleFunc("/access", accessReview)
|
http.HandleFunc("/access", accessReview)
|
||||||
http.HandleFunc("/clear", clearHistory)
|
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
|
key string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sorter recordSorter) sort() {
|
func (s recordSorter) sort() {
|
||||||
if sorter.ascending {
|
if s.ascending {
|
||||||
sort.Sort(sorter)
|
sort.Sort(s)
|
||||||
} else {
|
} else {
|
||||||
sort.Sort(sort.Reverse(sorter))
|
sort.Sort(sort.Reverse(s))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sorter recordSorter) Len() int {
|
func (s recordSorter) Len() int {
|
||||||
return len(sorter.entries)
|
return len(s.entries)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sorter recordSorter) Less(i, j int) bool {
|
func (s recordSorter) Less(i, j int) bool {
|
||||||
entry1 := sorter.entries[i]
|
entry1 := s.entries[i]
|
||||||
entry2 := sorter.entries[j]
|
entry2 := s.entries[j]
|
||||||
|
|
||||||
switch sorter.key {
|
switch s.key {
|
||||||
case "accessCount":
|
case "accessCount":
|
||||||
return entry1.accessCount < entry2.accessCount
|
return entry1.accessCount < entry2.accessCount
|
||||||
case "closestStn":
|
case "closestStn":
|
||||||
@ -174,6 +174,6 @@ func (sorter recordSorter) Less(i, j int) bool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sorter recordSorter) Swap(i, j int) {
|
func (s recordSorter) Swap(i, j int) {
|
||||||
sorter.entries[i], sorter.entries[j] = sorter.entries[j], sorter.entries[i]
|
s.entries[i], s.entries[j] = s.entries[j], s.entries[i]
|
||||||
}
|
}
|
||||||
|
3
util.go
3
util.go
@ -23,10 +23,11 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/kellydunn/golang-geo"
|
|
||||||
"log"
|
"log"
|
||||||
"math"
|
"math"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
|
"github.com/kellydunn/golang-geo"
|
||||||
)
|
)
|
||||||
|
|
||||||
func fixFeatures(features featureMap) featureMap {
|
func fixFeatures(features featureMap) featureMap {
|
||||||
|
Loading…
Reference in New Issue
Block a user