This picture shows the sample SSE implementation provided with this application. In the sample app, the server is sending timestamp every second, to all the clients.
Important: SSE is a live connection between server & client. So a short WriteTimeout duration in webgo.Config will keep dropping the connection. If you have any middleware which is setting deadlines or timeouts on the request.Context, will also effect these connections.
If you have Go installed on your computer, open the terminal and:
$ cd $GOPATH/src
$ mkdir -p github.com/bnkamalesh
$ cd github.com/bnkamalesh
$ git clone https://github.com/bnkamalesh/webgo.git
$ cd webgo
$ go run cmd/*.go
Info 2020/06/03 12:55:26 HTTP server, listening on :8080
Or if you have Docker, open the terminal and:
$ git clone https://github.com/bnkamalesh/webgo.git
$ cd webgo
$ docker run \
-p 8080:8080 \
-v ${PWD}:/go/src/github.com/bnkamalesh/webgo/ \
-w /go/src/github.com/bnkamalesh/webgo/cmd \
--rm -ti golang:latest go run *.go
Info 2020/06/03 12:55:26 HTTP server, listening on :8080
You can try the following API calls with the sample app. It also uses all the features provided by webgo
https://localhost:8080/
- Loads an HTML page
https://localhost:8080/matchall/
- Route with wildcard parameter configured
- All URIs which begin with
/matchall
will be matched because it has a wildcard variable - e.g.
https://localhost:8080/api/<param>
- Route with a named 'param' configured
- It will match all requests which match
/api/<single parameter>
- e.g.
https://localhost:8080/error-setter
- Route which sets an error and sets response status 500
https://localhost:8080/v5.4/api/<param>
- Route with a named 'param' configured
- It will match all requests which match
/v5.4/api/<single parameter>
- e.g.