aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/http/main.go43
-rw-r--r--examples/http/test.http42
2 files changed, 0 insertions, 85 deletions
diff --git a/examples/http/main.go b/examples/http/main.go
deleted file mode 100644
index 5c24867..0000000
--- a/examples/http/main.go
+++ /dev/null
@@ -1,43 +0,0 @@
-package main
-
-import (
- "context"
- "errors"
- "net/http"
-
- httpRPC "go.neonxp.dev/jsonrpc2/http"
- "go.neonxp.dev/jsonrpc2/rpc"
-)
-
-func main() {
- s := httpRPC.New()
-
- s.Register("multiply", rpc.Wrap(Multiply))
- s.Register("divide", rpc.Wrap(Divide))
-
- http.ListenAndServe(":8000", s)
-}
-
-func Multiply(ctx context.Context, args *Args) (int, error) {
- return args.A * args.B, nil
-}
-
-func Divide(ctx context.Context, args *Args) (*Quotient, error) {
- if args.B == 0 {
- return nil, errors.New("divide by zero")
- }
- quo := new(Quotient)
- quo.Quo = args.A / args.B
- quo.Rem = args.A % args.B
- return quo, nil
-}
-
-type Args struct {
- A int `json:"a"`
- B int `json:"b"`
-}
-
-type Quotient struct {
- Quo int `json:"quo"`
- Rem int `json:"rem"`
-}
diff --git a/examples/http/test.http b/examples/http/test.http
deleted file mode 100644
index d4e68b3..0000000
--- a/examples/http/test.http
+++ /dev/null
@@ -1,42 +0,0 @@
-POST http://localhost:8000/
-Content-Type: application/json
-
-{
- "jsonrpc": "2.0",
- "method": "multiply",
- "params": {
- "a": 2,
- "b": 3
- },
- "id": 1
-}
-
-###
-
-POST http://localhost:8000/
-Content-Type: application/json
-
-{
- "jsonrpc": "2.0",
- "method": "divide",
- "params": {
- "a": 10,
- "b": 3
- },
- "id": 2
-}
-
-###
-
-POST http://localhost:8000/
-Content-Type: application/json
-
-[
- { "jsonrpc": "2.0", "method": "multiply", "params": { "a": 2, "b": 3 }, "id": 10 },
- {"jsonrpc": "2.0", "method": "sum", "params": [1,2,4], "id": "1"},
- {"jsonrpc": "2.0", "method": "notify_hello", "params": [7]},
- {"jsonrpc": "2.0", "method": "subtract", "params": [42,23], "id": "2"},
- {"foo": "boo"},
- {"jsonrpc": "2.0", "method": "foo.get", "params": {"name": "myself"}, "id": "5"},
- {"jsonrpc": "2.0", "method": "get_data", "id": "9"}
-] \ No newline at end of file