Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
bobimicroweber committed Aug 17, 2024
1 parent 0041a60 commit 4c91090
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
3 changes: 2 additions & 1 deletion davi.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ func main() {
//$url = "https://api.open-meteo.com/v1/forecast?latitude=52.52&longitude=13.41&current=temperature_2m,wind_speed_10m&hourly=temperature_2m,relative_humidity_2m,wind_speed_10m";
//fileGetContents($url);
httpRegister("GET", "/hello");
httpRegister("/", "Cool!");
httpRegister("/hello", "Hello, World!");
httpListen(":3030");
`)
Expand Down
7 changes: 5 additions & 2 deletions interpreter/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -491,10 +491,13 @@ func httpRegisterFunction(interp *interpreter, pos Position, args []Value) Value
panic(typeError(pos, "httpRegisterFunction() requires 2 args, got %d", len(args)))
}

pattern := args[0].(string)
handler := args[1].(string)

getRoot := func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "Hello, Davinci!")
fmt.Fprintln(w, handler)
}
http.HandleFunc("/", getRoot)
http.HandleFunc(pattern, getRoot)

return Value(nil)

Expand Down
1 change: 1 addition & 0 deletions interpreter/functions/http_server.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package functions

0 comments on commit 4c91090

Please sign in to comment.