Skip to content

Commit 387d58b

Browse files
removed pkg, added conf package, cleaned up logging of requests
1 parent 95fff9b commit 387d58b

File tree

11 files changed

+52
-58
lines changed

11 files changed

+52
-58
lines changed

.gitignore

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,9 @@ test.out
1919
build.out
2020
_obj
2121

22-
# bin
23-
pkg/**/*
22+
# bin
23+
pkg
2424
bin
25-
src/*/*/_obj
26-
src/cmd/shock-server/shock-server
2725

2826
# os x files
2927
*.DS_Store

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ To build Shock:
4242

4343
To run (additional requires mongodb=>2.0.3):
4444

45-
./bin/shock-server -port=<port#> -dataroot=<path_to_data_root> -mongo=<mongo_host(s)>
45+
./bin/shock-server -port=<port to listen on> -data=<data directory to store on disk files> -mongo=<hostname(s) of mongodb>
4646

4747
Data Types
4848
----------
@@ -164,7 +164,7 @@ POST /node (multipart/form-data encoded)
164164
### List nodes:
165165
GET /node
166166

167-
- by adding ?offset=N you get the nodes starting at N+1
167+
- by adding ?skip=N you get the nodes starting at N+1
168168
- by adding ?limit=N you get a maximum of N nodes returned
169169

170170
##### querying
@@ -180,11 +180,11 @@ Multiple attributes can be selected in a single query and are treated as AND ope
180180

181181
/node/?query&metadata.env_biome=ENVO:human-associated%20habitat&about=metagenome
182182

183-
**Note** all special characters like a space must be url encoded.
183+
**Note:** all special characters like a space must be url encoded.
184184

185185
##### example
186186

187-
curl -X GET http://<shock_host>[:<port>]/node/[?offset=<offset>&limit=<count>][&query&<tag>=<value>]
187+
curl -X GET http://<shock_host>[:<port>]/node/[?skip=<skip>&limit=<count>][&query&<tag>=<value>]
188188
189189
##### returns
190190

-56.1 KB
Binary file not shown.

pkg/darwin_amd64/goweb.a

-505 KB
Binary file not shown.

pkg/darwin_amd64/shock/datastore.a

-309 KB
Binary file not shown.

src/shock/conf/conf.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package conf
2+
3+
import (
4+
"flag"
5+
)
6+
7+
// Command line options
8+
var (
9+
PORT = flag.Int("port", 8000, "port to listen on")
10+
DATAROOT = flag.String("data", "", "data directory to store on disk files")
11+
MONGODB = flag.String("mongodb", "localhost", "hostname(s) of mongodb")
12+
)
13+
14+
func init() {
15+
flag.Parse()
16+
}

src/shock/datastore/db.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package datastore
22

33
import (
4-
"fmt"
54
mgo "launchpad.net/mgo"
65
bson "launchpad.net/mgo/bson"
6+
conf "shock/conf"
77
)
88

99
type db struct {
@@ -12,8 +12,7 @@ type db struct {
1212
}
1313

1414
func DBConnect() (d *db, err error) {
15-
MONGODBHOST := "localhost"
16-
session, err := mgo.Dial(MONGODBHOST); if err != nil { return }
15+
session, err := mgo.Dial(*conf.MONGODB); if err != nil { return }
1716
d = &db{Nodes: session.DB("ShockDB").C("Nodes"), Session : session}
1817
return
1918
}
@@ -29,7 +28,6 @@ func (d *db) FindById(id string, result *Node) (err error) {
2928
}
3029

3130
func (d *db) GetAll(q bson.M, results *Nodes) (err error) {
32-
fmt.Println(q)
3331
err = d.Nodes.Find(q).All(results)
3432
return
3533
}

src/shock/datastore/node.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@ import (
1111
"io/ioutil"
1212
"strconv"
1313
bson "launchpad.net/mgo/bson"
14+
conf "shock/conf"
1415
)
1516

17+
func init() {}
18+
1619
// Node array type
1720
type Nodes []Node
1821

@@ -247,8 +250,7 @@ func (node *Node) setId() {
247250
}
248251

249252
func getPath(id string) (string) {
250-
DATAROOT := "/Users/jared/projects/GoShockData"
251-
return fmt.Sprintf("%s/%s/%s/%s/%s", DATAROOT, id[0:2], id[2:4], id[4:6], id)
253+
return fmt.Sprintf("%s/%s/%s/%s/%s", *conf.DATAROOT, id[0:2], id[2:4], id[4:6], id)
252254
}
253255

254256
func (node *Node) Path() (string) {

src/shock/shock-server/routes.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ type NodeController struct{}
3939
// multipart-form containing: data file and/or attributes (json file)
4040
// empty body
4141
func (cr *NodeController) Create(cx *goweb.Context) {
42-
fmt.Println("POST: /node")
42+
logReq(cx)
4343
params, files, err := ParseMultipartForm(cx.Request)
4444
if err != nil {
4545
if err.Error() == "request Content-Type isn't multipart/form-data" {
@@ -70,13 +70,14 @@ func (cr *NodeController) Create(cx *goweb.Context) {
7070

7171
// DELETE: /node/{id}
7272
func (cr *NodeController) Delete(id string, cx *goweb.Context) {
73-
fmt.Printf("DELETE: /node/%s\n", id)
73+
logReq(cx)
7474
cx.ResponseWriter.Header().Set("Content-Type", "application/json")
7575
fmt.Fprintf(cx.ResponseWriter, "{ \"message\" : \"delete operation currently not supported\" }")
7676
}
7777

7878
// DELETE: /node
7979
func (cr *NodeController) DeleteMany(cx *goweb.Context) {
80+
logReq(cx)
8081
cx.ResponseWriter.Header().Set("Content-Type", "application/json")
8182
fmt.Fprintf(cx.ResponseWriter, "{ \"message\" : \"deletemany operation currently not supported\" }")
8283
}
@@ -86,7 +87,7 @@ func (cr *NodeController) DeleteMany(cx *goweb.Context) {
8687
// ?pipe(&{func}={funcOptions})+)
8788
// ?list={indexes||functions||parts&index={index}...}
8889
func (cr *NodeController) Read(id string, cx *goweb.Context) {
89-
fmt.Printf("GET: /node/%s\n", id)
90+
logReq(cx)
9091
query := cx.Request.URL.Query()
9192
_, download := query["download"]
9293
_, pipe := query["pipe"]
@@ -120,16 +121,16 @@ func (cr *NodeController) Read(id string, cx *goweb.Context) {
120121
// ?paginate[&limit={limit}&offset={offset}]
121122
// ?query={queryString}[&paginate[&limit={limit}&offset={offset}]]
122123
func (cr *NodeController) ReadMany(cx *goweb.Context) {
123-
fmt.Printf("GET: /node\n")
124+
logReq(cx)
124125
query := cx.Request.URL.Query()
125126
l, hasLimit := query["limit"]
126-
o, hasOffset := query["offset"]
127+
o, hasOffset := query["skip"]
127128
_, hasQuery := query["query"]
128129

129130
q := bson.M{}
130131
nodes := new(ds.Nodes)
131132

132-
skip := map[string]int{"limit" : 1,"offset" : 1,"query" : 1}
133+
skip := map[string]int{"limit" : 1,"skip" : 1,"query" : 1}
133134
if hasQuery {
134135
for key, val := range query {
135136
_, s := skip[key]
@@ -140,7 +141,6 @@ func (cr *NodeController) ReadMany(cx *goweb.Context) {
140141
}
141142
if hasLimit || hasOffset {
142143
var lim, off int
143-
fmt.Printf("limit: %s, offset: %s\n", l[0], o[0])
144144
if !hasLimit {
145145
lim = 100
146146
} else {
@@ -174,8 +174,7 @@ func (cr *NodeController) ReadMany(cx *goweb.Context) {
174174
// ?index={type}[&options={options}]
175175
// ?file[&part={part}]
176176
func (cr *NodeController) Update(id string, cx *goweb.Context) {
177-
fmt.Printf("PUT: /node/%s\n", id)
178-
177+
logReq(cx)
179178
node, err := ds.LoadNode(id); if err != nil {
180179
// add node not found message
181180
cx.RespondWithError(http.StatusBadRequest)
@@ -208,6 +207,7 @@ func (cr *NodeController) Update(id string, cx *goweb.Context) {
208207

209208
// PUT: /node
210209
func (cr *NodeController) UpdateMany(cx *goweb.Context) {
210+
logReq(cx)
211211
cx.ResponseWriter.Header().Set("Content-Type", "application/json")
212212
fmt.Fprintf(cx.ResponseWriter, "{ \"message\" : \"updatemany operation currently not supported\" }")
213213
}
Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,15 @@
11
package main
22

33
import (
4-
"flag"
54
"fmt"
65
"goweb"
6+
conf "shock/conf"
77
)
88

9-
// Command line options
10-
var (
11-
PORT = flag.Int("port", 8000, "the port to listen on")
12-
DATAROOT = "/Users/jared/projects/GoShockData"
13-
)
14-
15-
func init() {}
16-
179
func main() {
18-
flag.Parse()
1910
goweb.ConfigureDefaultFormatters()
2011
goweb.MapRest("/node", new(NodeController))
21-
fmt.Printf("Shock port:%d...starting\n", *PORT)
22-
goweb.ListenAndServe(":"+fmt.Sprintf("%d", *PORT))
12+
fmt.Printf("Shock port:%d...starting\n", *conf.PORT)
13+
goweb.ListenAndServe(":"+fmt.Sprintf("%d", *conf.PORT))
2314

24-
}
25-
26-
/*
27-
n, err := ds.CreateNode("/Users/jared/ANL/Apr_Day_pf.fas", "test.json")
28-
if err != nil {
29-
fmt.Println("hells bells: " + err.String())
30-
}
31-
err = n.Save()
32-
if err != nil {
33-
fmt.Println("hells bells: " + err.String())
34-
}
35-
fmt.Println(n.ToJson())
36-
fmt.Println(n.Path())
37-
*/
38-
39-
/*
40-
n, err = LoadNode("bf6d2f5b9611cb4ebe28d79f25cd65f4")
41-
if err != nil {
42-
fmt.Println("hells bells: " + err.String())
43-
}
44-
fmt.Println(n.ToJson())
45-
*/
15+
}

0 commit comments

Comments
 (0)