event/

directory
v4.0.0-...-5ab2063 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 24, 2023 License: Apache-2.0

README

Event

This example demonstrates how to handle event between client and server.

  1. Client will publish access event when handle http request.
  2. Server will subscribe access event and update access statistics.

Protobuf

protoc --go_out=proto --micro_out=proto proto/statistics.proto

Run Server

go run event/server/main.go event/server/handler.go event/server/subscriber.go
Tips

Panic recover is required in subscribe method to prevent crash when panic occur in subscribe goroutine.

Run Client

go run event/client/main.go

Testing

curl -X POST http://localhost:80/helloworld?user=test
{"message":"Hello test"}
curl -X GET http://localhost:80/statistics?method=POST
{"access_count":1}
curl -X GET http://localhost:80/statistics?method=GET
{"access_count":1}
curl -X GET http://localhost:80/statistics
{"access_count":3}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL