diff options
author | Alexander Kiryukhin <a.kiryukhin@mail.ru> | 2022-05-29 14:18:10 +0300 |
---|---|---|
committer | Alexander Kiryukhin <a.kiryukhin@mail.ru> | 2022-05-29 14:18:10 +0300 |
commit | 3d5463c820b6fd32805caf53dedbddfea9c5bae9 (patch) | |
tree | 186a42d564c2212eb321fba968e679e3abc24a5d /example | |
parent | f304a07a8cfe67b2a65f95f27eb10a9b854c4ef8 (diff) |
Better validationv1.1.2
Diffstat (limited to 'example')
-rw-r--r-- | example/main.go | 34 |
1 files changed, 27 insertions, 7 deletions
diff --git a/example/main.go b/example/main.go index 11e1fb0..37b9037 100644 --- a/example/main.go +++ b/example/main.go @@ -7,7 +7,6 @@ import ( "os" "os/signal" - "github.com/qri-io/jsonschema" "go.neonxp.dev/jsonrpc2/rpc" "go.neonxp.dev/jsonrpc2/rpc/middleware" "go.neonxp.dev/jsonrpc2/transport" @@ -18,10 +17,12 @@ func main() { rpc.WithLogger(rpc.StdLogger), rpc.WithTransport(&transport.HTTP{Bind: ":8000", CORSOrigin: "*"}), ) + // Set options after constructor - validation, err := middleware.Validation(map[string]middleware.MethodSchema{ + serviceSchema := ` + { "divide": { - Request: *jsonschema.Must(`{ + "request": { "type": "object", "properties": { "a": { @@ -33,8 +34,8 @@ func main() { } }, "required": ["a", "b"] - }`), - Response: *jsonschema.Must(`{ + }, + "response": { "type": "object", "properties": { "quo": { @@ -45,9 +46,28 @@ func main() { } }, "required": ["quo", "rem"] - }`), + } }, - }) + "multiply": { + "request": { + "type": "object", + "properties": { + "a": { + "type": "integer" + }, + "b": { + "type": "integer" + } + }, + "required": ["a", "b"] + }, + "response": { + "type": "integer" + } + } + }` + + validation, err := middleware.Validation(middleware.MustSchema(serviceSchema)) if err != nil { log.Fatal(err) } |