-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper.go
70 lines (61 loc) · 1.99 KB
/
helper.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package main
import (
"database/sql"
"fmt"
"net/http"
)
// ------------------------------------------------------------------------
// --------------------------------- DB ---------------------------------
// ------------------------------------------------------------------------
func openDB() (*sql.DB, error) {
db, db_err := sql.Open("sqlite3", DATABASE_PATH)
if db_err != nil {
return nil, fmt.Errorf("Unable to open database : %s", db_err.Error())
}
return db, nil
}
// ------------------------------------------------------------------------
// --------------------------------- Misc ---------------------------------
// ------------------------------------------------------------------------
func sortInterfaceSlice(s [][]interface{}, ind int) [][]interface{} {
ret := [][]interface{}{}
var max_min int = 0
for i := 0; i < len(s); i++ {
var x int
var min int = 1000000
var index int
for a, b := range s {
switch b[ind].(type) {
case int64:
x = int(b[ind].(int64))
case int:
x = int(b[ind].(int64))
case float32:
x = int(b[ind].(int64))
case float64:
x = int(b[ind].(int64))
default:
x = int(b[ind].(int64))
}
if x < min && x > max_min {
min = x
index = a
}
}
max_min = min
ret = append(ret, s[index])
}
return ret
}
// ---------------------------------------------------------------------------
// --------------------------------- Web ---------------------------------
// ---------------------------------------------------------------------------
func healthyRequestHandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "running")
}
// ---------------------------------------------------------------------------
// --------------------------------- Testing ---------------------------------
// ---------------------------------------------------------------------------
func prettify(expectation string, actual string) string {
return fmt.Sprintf("\n\t[ WANTED ] %s\n\t[ ACTUAL ] %s\n\n", expectation, actual)
}