aboutsummaryrefslogtreecommitdiff
path: root/example
diff options
context:
space:
mode:
authorAlexander Kiryukhin <a.kiryukhin@mail.ru>2022-05-22 16:37:48 +0300
committerAlexander Kiryukhin <a.kiryukhin@mail.ru>2022-05-22 16:37:48 +0300
commit4a81eff217c40c459c9a9ed4f318b4dd9bc5ee8a (patch)
tree35e6d3b1f80af80fddedb26d5543377931abfe2f /example
parentc74596c6a6a741e3365a2f372de6e7cdf2583fdc (diff)
Middlewares and optionsv1.1.0
Diffstat (limited to 'example')
-rw-r--r--example/main.go13
-rw-r--r--example/test.http36
2 files changed, 9 insertions, 40 deletions
diff --git a/example/main.go b/example/main.go
index 9f25e61..d5d034e 100644
--- a/example/main.go
+++ b/example/main.go
@@ -12,10 +12,15 @@ import (
)
func main() {
- s := rpc.New()
-
- s.AddTransport(&transport.HTTP{Bind: ":8000"})
- s.AddTransport(&transport.TCP{Bind: ":3000"})
+ s := rpc.New(
+ rpc.WithLogger(rpc.StdLogger),
+ rpc.WithTransport(&transport.HTTP{Bind: ":8000", CORSOrigin: "*"}),
+ )
+ // Set options after constructor
+ s.Use(
+ rpc.WithTransport(&transport.TCP{Bind: ":3000"}),
+ rpc.WithMiddleware(rpc.LoggerMiddleware(rpc.StdLogger)),
+ )
s.Register("multiply", rpc.H(Multiply))
s.Register("divide", rpc.H(Divide))
diff --git a/example/test.http b/example/test.http
index 7ed134a..e126917 100644
--- a/example/test.http
+++ b/example/test.http
@@ -11,18 +11,6 @@ Content-Type: application/json
}
-date: Sat, 21 May 2022 16:53:31 GMT
-content-length: 36
-content-type: text/plain; charset=utf-8
-connection: close
-
-HTTP/1.1 200 - OK
-date: Sat, 21 May 2022 16:53:31 GMT
-content-length: 36
-content-type: text/plain; charset=utf-8
-connection: close
-
-
###
POST http://localhost:8000/
Content-Type: application/json
@@ -37,18 +25,6 @@ Content-Type: application/json
}
-date: Sat, 21 May 2022 16:53:51 GMT
-content-length: 52
-content-type: text/plain; charset=utf-8
-connection: close
-
-HTTP/1.1 200 - OK
-date: Sat, 21 May 2022 16:53:51 GMT
-content-length: 52
-content-type: text/plain; charset=utf-8
-connection: close
-
-
### Batch request
POST http://localhost:8000/
Content-Type: application/json
@@ -68,15 +44,3 @@ Content-Type: application/json
{"foo": "boo"}
{"jsonrpc": "2.0", "method": "foo.get", "params": {"name": "myself"}, "id": "5"}
{"jsonrpc": "2.0", "method": "get_data", "id": "9"}
-
-
-date: Sat, 21 May 2022 17:18:17 GMT
-content-type: text/plain; charset=utf-8
-connection: close
-transfer-encoding: chunked
-
-HTTP/1.1 200 - OK
-date: Sat, 21 May 2022 17:18:17 GMT
-content-type: text/plain; charset=utf-8
-connection: close
-transfer-encoding: chunked \ No newline at end of file