Skip to content

Commit c499d48

Browse files
committed
Added handlers for length and status checks.
1 parent 2247bd5 commit c499d48

5 files changed

Lines changed: 15 additions & 5 deletions

File tree

bin/helldb-darwin-amd64

6.44 MB
Binary file not shown.

bin/helldb-linux-amd64

6.45 MB
Binary file not shown.

portal/evaluator/evaluator.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"helldb/query/parser"
1313
)
1414

15-
var store = s.Init()
15+
var Store = s.Init()
1616

1717
func REPL(prompt string) {
1818
fmt.Println("helldb client v0.0.1")
@@ -21,7 +21,7 @@ func REPL(prompt string) {
2121
for scanner.Scan() {
2222
input := scanner.Text()
2323
if input == "dumb" {
24-
fmt.Println(store.JSON())
24+
fmt.Println(Store.JSON())
2525
fmt.Print(prompt)
2626
continue
2727
}
@@ -46,15 +46,15 @@ func Eval(input string) Response {
4646
var keys []string
4747
if isGet {
4848
keys = keysFromGetStatement(statement)
49-
results[i] = store.Get(keys)
49+
results[i] = Store.Get(keys)
5050
} else {
5151
keys = keysFromDelStatement(statement)
52-
results[i] = store.Del(keys)
52+
results[i] = Store.Del(keys)
5353
}
5454
} else {
5555
putStatement := statement.(*ast.PutStatement)
5656
key, value := putStatement.Key.String(), putStatement.Value
57-
store.Put(key, ast.ExtractToBaseType(value))
57+
Store.Put(key, ast.ExtractToBaseType(value))
5858
results[i] = nil
5959
}
6060
}

portal/server/handlers.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,11 @@ func query(w http.ResponseWriter, r *http.Request) {
2020
_, _ = fmt.Fprint(w, toJson(newError("query not provided")))
2121
}
2222
}
23+
24+
func status(w http.ResponseWriter, _ *http.Request) {
25+
_, _ = fmt.Fprint(w, "ok")
26+
}
27+
28+
func length(w http.ResponseWriter, _ *http.Request) {
29+
_, _ = fmt.Fprintf(w, "%d", evaluator.Store.Len())
30+
}

portal/server/server.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import (
88
func Serve(port string) {
99

1010
http.HandleFunc("/query", query)
11+
http.HandleFunc("/status", status)
12+
http.HandleFunc("/length", length)
1113

1214
log.Printf("serving hell on http://localhost:%s\n", port)
1315
log.Fatal(http.ListenAndServe(":"+port, nil))

0 commit comments

Comments
 (0)