-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
77 lines (65 loc) · 1.85 KB
/
main.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
71
72
73
74
75
76
77
// Copyright (C) 2016 JT Olds
// See LICENSE for copying information
package main
import (
"flag"
"fmt"
"net/http"
"os"
"github.com/jtolds/golincs/web/dbs"
"github.com/jtolds/golincs/web/dbs/lincs_gse92742_v0"
"gopkg.in/webhelp.v1/whfatal"
"gopkg.in/webhelp.v1/whlog"
"gopkg.in/webhelp.v1/whmux"
"gopkg.in/webhelp.v1/whredir"
"gopkg.in/webhelp.v1/whroute"
)
var (
listenAddr = flag.String("addr", ":8080", "address to listen on")
sampleId = whmux.NewStringArg()
geneSigId = whmux.NewStringArg()
genesetId = whmux.NewStringArg()
)
func main() {
flag.Parse()
lincs_92742, err := lincs_gse92742_v0.New()
if err != nil {
panic(err)
}
datasetMux := whmux.Dir{"": whredir.RedirectHandler("/")}
datasets := []dbs.Dataset{lincs_92742}
for id, dataset := range datasets {
endpoints := NewEndpoints(struct {
dbs.Dataset
Id int
}{Dataset: dataset, Id: id})
datasetMux[fmt.Sprint(id)] = whmux.Dir{
"": whmux.Exact(http.HandlerFunc(endpoints.Dataset)),
"sample": sampleId.Shift(
whmux.Exact(http.HandlerFunc(endpoints.Sample))),
"genesig": geneSigId.Shift(
whmux.Exact(http.HandlerFunc(endpoints.GeneSig))),
"geneset": genesetId.Shift(
whmux.Exact(http.HandlerFunc(endpoints.Geneset))),
"search": whmux.Dir{
"keyword": whmux.Exact(http.HandlerFunc(endpoints.Keyword)),
"signature": whmux.Exact(http.HandlerFunc(endpoints.Signature)),
},
}
}
routes := whlog.LogRequests(whlog.Default, whfatal.Catch(whmux.Dir{
"": whmux.Exact(http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) {
Render("datasets", map[string]interface{}{"datasets": datasets})
})),
"dataset": datasetMux,
}))
switch flag.Arg(0) {
case "serve":
panic(whlog.ListenAndServe(*listenAddr, routes))
case "routes":
whroute.PrintRoutes(os.Stdout, routes)
default:
fmt.Printf("Usage: %s <serve|routes>\n", os.Args[0])
}
}