Skip to content

Commit cc2bb0c

Browse files
authored
Pusher (#44)
[minor] implement HTTP2 push [-] replaced travis settings with Github actions [-] sample app updated to show HTTP2 push usage
1 parent 8a92a16 commit cc2bb0c

22 files changed

+391
-98
lines changed

.github/workflows/golangci-lint.yml

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: golangci-lint
2+
on:
3+
push:
4+
tags:
5+
- v*
6+
branches:
7+
- master
8+
- main
9+
pull_request:
10+
permissions:
11+
contents: read
12+
# Optional: allow read access to pull request. Use with `only-new-issues` option.
13+
# pull-requests: read
14+
jobs:
15+
golangci:
16+
name: Static analysis
17+
runs-on: ubuntu-latest
18+
steps:
19+
- uses: actions/setup-go@v3
20+
with:
21+
go-version: 1.18
22+
- uses: actions/checkout@v3
23+
- name: golangci-lint
24+
uses: golangci/golangci-lint-action@v3
25+
with:
26+
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
27+
version: latest
28+
29+
# Optional: working directory, useful for monorepos
30+
# working-directory: somedir
31+
32+
# Optional: golangci-lint command line arguments.
33+
# args: --issues-exit-code=0
34+
35+
# Optional: show only new issues if it's a pull request. The default value is `false`.
36+
# only-new-issues: true
37+
38+
# Optional: if set to true then the all caching functionality will be complete disabled,
39+
# takes precedence over all other caching options.
40+
# skip-cache: true
41+
42+
# Optional: if set to true then the action don't cache or restore ~/go/pkg.
43+
# skip-pkg-cache: true
44+
45+
# Optional: if set to true then the action don't cache or restore ~/.cache/go-build.
46+
# skip-build-cache: true

.github/workflows/tests.yaml

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
branches:
9+
- master
10+
jobs:
11+
testold:
12+
name: "Test with Go 1.13"
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v3
16+
17+
- name: Set up Go 1.13
18+
uses: actions/setup-go@v3
19+
with:
20+
go-version: 1.13
21+
22+
- name: Test
23+
run: go test -coverprofile=coverage.txt -covermode=atomic $(go list ./... | grep -v /cmd)
24+
25+
testlatest:
26+
name: "Test with default latest Go"
27+
runs-on: ubuntu-latest
28+
steps:
29+
- uses: actions/checkout@v3
30+
31+
- name: Set up Go latest
32+
uses: actions/setup-go@v3
33+
34+
- name: Test
35+
run: go test -coverprofile=coverage.txt -covermode=atomic $(go list ./... | grep -v /cmd)

.travis.yml

-18
This file was deleted.

README.md

+24-25
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
<p align="center"><img src="https://user-images.githubusercontent.com/1092882/60883564-20142380-a268-11e9-988a-d98fb639adc6.png" alt="webgo gopher" width="256px"/></p>
22

3-
[![](https://travis-ci.org/bnkamalesh/webgo.svg?branch=master)](https://travis-ci.org/bnkamalesh/webgo)
3+
[![](https://github.com/bnkamalesh/webgo/actions/workflows/tests.yaml/badge.svg)](https://github.com/bnkamalesh/webgo/actions/workflows/tests.yaml)
44
[![coverage](https://img.shields.io/codecov/c/github/bnkamalesh/webgo.svg)](https://codecov.io/gh/bnkamalesh/webgo)
55
[![](https://goreportcard.com/badge/github.com/bnkamalesh/webgo)](https://goreportcard.com/report/github.com/bnkamalesh/webgo)
66
[![](https://api.codeclimate.com/v1/badges/85b3a55c3fa6b4c5338d/maintainability)](https://codeclimate.com/github/bnkamalesh/webgo/maintainability)
77
[![](https://godoc.org/github.com/nathany/looper?status.svg)](http://godoc.org/github.com/bnkamalesh/webgo)
88
[![](https://awesome.re/mentioned-badge.svg)](https://github.com/avelino/awesome-go#web-frameworks)
99

10-
# WebGo v6.6.6
10+
# WebGo v6.7.0
1111

12-
WebGo is a minimalistic framework for [Go](https://golang.org) to build web applications (server side) with no 3rd party dependencies. WebGo will always be Go standard library compliant; with the HTTP handlers having the same signature as [http.HandlerFunc](https://golang.org/pkg/net/http/#HandlerFunc).
12+
WebGo is a minimalistic router for [Go](https://golang.org) to build web applications (server side) with no 3rd party dependencies. WebGo will always be Go standard library compliant; with the HTTP handlers having the same signature as [http.HandlerFunc](https://golang.org/pkg/net/http/#HandlerFunc).
1313

1414
### Contents
1515

@@ -24,21 +24,20 @@ WebGo is a minimalistic framework for [Go](https://golang.org) to build web appl
2424
9. [Server-Sent Events](https://github.com/bnkamalesh/webgo#server-sent-events)
2525
10. [Usage](https://github.com/bnkamalesh/webgo#usage)
2626

27-
2827
## Router
2928

30-
Webgo has a simplistic, regex based router and supports defining [URI](https://developer.mozilla.org/en-US/docs/Glossary/URI)s with the following patterns
29+
Webgo has a simplistic, linear path matching router and supports defining [URI](https://developer.mozilla.org/en-US/docs/Glossary/URI)s with the following patterns
3130

3231
1. `/api/users` - URI with no dynamic values
33-
2. `/api/users/:userID`
34-
- URI with a named parameter, `userID`
35-
- If TrailingSlash is set to true, it will accept the URI ending with a '/', refer to [sample](https://github.com/bnkamalesh/webgo#sample)
32+
2. `/api/users/:userID`
33+
- URI with a named parameter, `userID`
34+
- If TrailingSlash is set to true, it will accept the URI ending with a '/', refer to [sample](https://github.com/bnkamalesh/webgo#sample)
3635
3. `/api/users/:misc*`
37-
- Named URI parameter `misc`, with a wildcard suffix '*'
38-
- This matches everything after `/api/users`. e.g. `/api/users/a/b/c/d`
36+
- Named URI parameter `misc`, with a wildcard suffix '\*'
37+
- This matches everything after `/api/users`. e.g. `/api/users/a/b/c/d`
3938

4039
When there are multiple handlers matching the same URI, only the first occurring handler will handle the request.
41-
Refer to the [sample](https://github.com/bnkamalesh/webgo#sample) to see how routes are configured. You can access named parameters of the URI using the `Context` function.
40+
Refer to the [sample](https://github.com/bnkamalesh/webgo#sample) to see how routes are configured. You can access named parameters of the URI using the `Context` function.
4241

4342
Note: webgo Context is **not** available inside the special handlers (not found & method not implemented)
4443

@@ -53,9 +52,9 @@ func helloWorld(w http.ResponseWriter, r *http.Request) {
5352
webgo.R200(
5453
w,
5554
fmt.Sprintf(
56-
"Route name: '%s', params: '%s'",
55+
"Route name: '%s', params: '%s'",
5756
route.Name,
58-
params,
57+
params,
5958
),
6059
)
6160
}
@@ -71,7 +70,7 @@ WebGo [middlware](https://godoc.org/github.com/bnkamalesh/webgo#Middleware) lets
7170

7271
NotFound && NotImplemented are considered `Special` handlers. `webgo.Context(r)` within special handlers will return `nil`.
7372

74-
Any number of middleware can be added to the router, the order of execution of middleware would be [LIFO](https://en.wikipedia.org/wiki/Stack_(abstract_data_type)) (Last In First Out). i.e. in case of the following code
73+
Any number of middleware can be added to the router, the order of execution of middleware would be [LIFO](<https://en.wikipedia.org/wiki/Stack_(abstract_data_type)>) (Last In First Out). i.e. in case of the following code
7574

7675
```golang
7776
func main() {
@@ -92,23 +91,23 @@ WebGo provides a few helper functions. When using `Send` or `SendResponse` (othe
9291

9392
```json
9493
{
95-
"data": "<any valid JSON payload>",
96-
"status": "<HTTP status code, of type integer>"
94+
"data": "<any valid JSON payload>",
95+
"status": "<HTTP status code, of type integer>"
9796
}
9897
```
9998

10099
When using `SendError`, the response is wrapped in WebGo's [error response struct](https://github.com/bnkamalesh/webgo/blob/master/responses.go#L23) and is serialzied as JSON.
101100

102101
```json
103102
{
104-
"errors": "<any valid JSON payload>",
105-
"status": "<HTTP status code, of type integer>"
103+
"errors": "<any valid JSON payload>",
104+
"status": "<HTTP status code, of type integer>"
106105
}
107106
```
108107

109108
## HTTPS ready
110109

111-
HTTPS server can be started easily, by providing the key & cert file. You can also have both HTTP & HTTPS servers running side by side.
110+
HTTPS server can be started easily, by providing the key & cert file. You can also have both HTTP & HTTPS servers running side by side.
112111

113112
Start HTTPS server
114113

@@ -180,14 +179,12 @@ func main() {
180179
// }
181180
}()
182181

183-
signal.Notify(osSig, os.Interrupt, syscall.SIGTERM)
182+
go func(){
183+
time.Sleep(time.Second*15)
184+
signal.Notify(osSig, os.Interrupt, syscall.SIGTERM)
185+
}()
184186

185187
router.Start()
186-
187-
for {
188-
// Prevent main thread from exiting, and wait for shutdown to complete
189-
time.Sleep(time.Second * 1)
190-
}
191188
}
192189
```
193190

@@ -202,9 +199,11 @@ The default logger uses Go standard library's `log.Logger` with `os.Stdout` (for
202199
## Server-Sent Events
203200

204201
[MDN has a very good documentation of what SSE (Server-Sent Events)](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events) are. The sample app provided shows how to use the SSE extension of webgo.
202+
205203
## Usage
206204

207205
A fully functional sample is provided [here](https://github.com/bnkamalesh/webgo/blob/master/cmd/main.go).
206+
208207
### Benchmark
209208

210209
1. [the-benchmarker](https://github.com/the-benchmarker/web-frameworks)

cmd/README.md

+32-29
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77
This picture shows the sample SSE implementation provided with this application. In the sample app, the server is
88
sending timestamp every second, to all the clients.
99

10-
**Important**: *[SSE](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events)
11-
is a live connection between server & client. So a short WriteTimeout duration in webgo.Config will
12-
keep dropping the connection. If you have any middleware which is setting deadlines or timeouts on the
13-
request.Context, will also effect these connections.*
14-
## How to run
10+
**Important**: _[SSE](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events)
11+
is a live connection between server & client. So a short WriteTimeout duration in webgo.Config will
12+
keep dropping the connection. If you have any middleware which is setting deadlines or timeouts on the
13+
request.Context, will also effect these connections._
14+
15+
## How to run
1516

1617
If you have Go installed on your computer, open the terminal and:
1718

@@ -20,10 +21,11 @@ $ cd $GOPATH/src
2021
$ mkdir -p github.com/bnkamalesh
2122
$ cd github.com/bnkamalesh
2223
$ git clone https://github.com/bnkamalesh/webgo.git
23-
$ cd webgo
24-
$ go run cmd/*.go
24+
$ cd webgo/cmd
25+
$ go run *.go
2526

26-
Info 2020/06/03 12:55:26 HTTP server, listening on :8080
27+
Info 2023/02/05 08:51:26 HTTP server, listening on :8080
28+
Info 2023/02/05 08:51:26 HTTPS server, listening on :9595
2729
```
2830

2931
Or if you have [Docker](https://www.docker.com/), open the terminal and:
@@ -33,36 +35,37 @@ $ git clone https://github.com/bnkamalesh/webgo.git
3335
$ cd webgo
3436
$ docker run \
3537
-p 8080:8080 \
38+
-p 9595:9595 \
3639
-v ${PWD}:/go/src/github.com/bnkamalesh/webgo/ \
3740
-w /go/src/github.com/bnkamalesh/webgo/cmd \
3841
--rm -ti golang:latest go run *.go
3942

40-
Info 2020/06/03 12:55:26 HTTP server, listening on :8080
43+
Info 2023/02/05 08:51:26 HTTP server, listening on :8080
44+
Info 2023/02/05 08:51:26 HTTPS server, listening on :9595
4145
```
4246

43-
4447
You can try the following API calls with the sample app. It also uses all the features provided by webgo
4548

4649
1. `http://localhost:8080/`
47-
- Loads an HTML page
50+
- Loads an HTML page
4851
2. `http://localhost:8080/matchall/`
49-
- Route with wildcard parameter configured
50-
- All URIs which begin with `/matchall` will be matched because it has a wildcard variable
51-
- e.g.
52-
- http://localhost:8080/matchall/hello
53-
- http://localhost:8080/matchall/hello/world
54-
- http://localhost:8080/matchall/hello/world/user
52+
- Route with wildcard parameter configured
53+
- All URIs which begin with `/matchall` will be matched because it has a wildcard variable
54+
- e.g.
55+
- http://localhost:8080/matchall/hello
56+
- http://localhost:8080/matchall/hello/world
57+
- http://localhost:8080/matchall/hello/world/user
5558
3. `http://localhost:8080/api/<param>`
56-
- Route with a named 'param' configured
57-
- It will match all requests which match `/api/<single parameter>`
58-
- e.g.
59-
- http://localhost:8080/api/hello
60-
- http://localhost:8080/api/world
59+
- Route with a named 'param' configured
60+
- It will match all requests which match `/api/<single parameter>`
61+
- e.g.
62+
- http://localhost:8080/api/hello
63+
- http://localhost:8080/api/world
6164
4. `http://localhost:8080/error-setter`
62-
- Route which sets an error and sets response status 500
63-
5. `http://localhost:8080/v5.4/api/<param>`
64-
- Route with a named 'param' configured
65-
- It will match all requests which match `/v5.4/api/<single parameter>`
66-
- e.g.
67-
- http://localhost:8080/v5.4/api/hello
68-
- http://localhost:8080/v5.4/api/world
65+
- Route which sets an error and sets response status 500
66+
5. `http://localhost:8080/v6.7/api/<param>`
67+
- Route with a named 'param' configured
68+
- It will match all requests which match `/v6.7/api/<single parameter>`
69+
- e.g.
70+
- http://localhost:8080/v6.7/api/hello
71+
- http://localhost:8080/v6.7/api/world

cmd/certs/CA.key

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
-----BEGIN RSA PRIVATE KEY-----
2+
Proc-Type: 4,ENCRYPTED
3+
DEK-Info: DES-EDE3-CBC,3172865781AB630D
4+
5+
b65fTCSGMadtvR5GnVfTsssu9qrQgm5XNCXRJ+PLpuXuWdywORTOEM4/FtRA62AN
6+
f41Dl/OO7nUNTTF4J+0fNiLMmnkiYvGSa5lcjRqBikk6waZjYkSUoo4TdGh502F/
7+
jFzbGzqXlX0qt+pj0HY/fhKxpr45bOkBr9S3ucMbgyuREX1HShxF759Mc+sJFx7w
8+
Ghs+byTL3cZABHRn/0xpC9S/PhEnsW3dPPJItCkEUsLumwTFCuaGskpP3chuVhZh
9+
36p74An+Tg9wlgcaCaUSUHWs22rnLBHAjv9JzVuoLJWdUwIYrcQTJz2+8mVlun24
10+
Qns7dhRafOHlIeOCxI/fmKlXE/S9S7tuXaMsHtqGK/22MAXJx/AOymjfgXfTLnF1
11+
XmLK0FTyp9BB1pfW9P+D6JEp7bj1fRHZeCOkesJOjyDEb+v+oYMaha6IVfQCMKQf
12+
P1+okMwBPGQIAr5d4Ov82mwpDyO1+rHAFn3b3zuro4rfHiHPDTo9Oa7EtMBIWZgj
13+
Ln0KLeaRkPht6wSUubCSl8Ypg27xbHwbQbWcQsr/OwLgWMJ40/1QKaqYIDV4LytZ
14+
mSzwwo4kQASKI1jwFWff+4yVqd3SuyW5uGcPNnkbneyKZzFHd/rAWnsT9cIIOX0v
15+
US5LEn9r+qjYk+ZVCSgqmrwUHyPfbx/BeARJTDBzo2jJC+ZiR7UkzD54r5pzs7R4
16+
9N3hVVmocS9BNPj45ioLw/Fhbu62N34NkRdDAisPhlQ+yM7klKBciQsEsKj1c6iw
17+
QwJNScvgW6x0+47J+tp21KLuxdfVP+Bq9wSb2B4kR3l93/ZAXR1S0cg0cuez1frd
18+
8g1kpQMzxhWVMzB6NHG7wAIo7p947mueP3Ggh1rgA6WLTltvH11ywadglG23HB7R
19+
zuxcQqoPm7Tzcift316DE5Q+qipHDA2UmiWZ83ZVQCshiJxILsPkGbh7k+mRwRyh
20+
e08TLEJMtCWiqvCmxHbebx7y8+oX035QIUVIOxHGier2CyZtgpaZyeEa4DHZCwuH
21+
ZrTMfigGDSXnonCrVtsC9zSYGQav/tRVxahKsM/TA+O1gOWNTncEe2ESKWaBzJpQ
22+
wUo7u/e/hbyPxMd2ezmeYVWwRSy9J/uZOsH0DsUlGsUzTWj+qrbmrdDYGVI2sgA1
23+
xfTfv7vdLFpESDRV4eRWscblusHffjCFA9oC9Y9qj2M8X+HLa/EELMb5CCWGZm3E
24+
HMZKwg6cah5rc82FFk0nDTzNpw57rTorPOGDe3oUif2NR+A4gxyepVrNDBFxDzbd
25+
PT2YMPr2IsHgxnRwFyoAPGG3rKCO+rFNJKcfrxvdeTj7mZ0Yzo93f9ycgNhqDKnR
26+
+n8vCWtWnRuDu8hk3d5YjhaZux/SmOuF9G6VX0jnJA534aLhEo0mzddGKM0bnOGN
27+
J1aMc65s4rPqUOQiase/3w7fNDu6szF/tcUMEWPRCDymZpZ9yznK122ajQVrKyOq
28+
HDcftg1rrKli8I/AljJMgC9ACZ9YfOfZ3qymcY7X7ZJyMucKi822ajIggi630aJQ
29+
sEqwxl5coM/N+Rhcp2/NiYyq3MXQBibKhq00OBLq76QQeNsJbRhUDw==
30+
-----END RSA PRIVATE KEY-----

cmd/certs/CA.pem

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
-----BEGIN CERTIFICATE-----
2+
MIIDijCCAnICCQCImGKiTiq7ITANBgkqhkiG9w0BAQsFADCBhjELMAkGA1UEBhMC
3+
SU4xCzAJBgNVBAgMAktBMRIwEAYDVQQHDAlCZW5nYWx1cnUxFTATBgNVBAoMDERl
4+
bGl2ZXJ5SGVybzETMBEGA1UECwwKUS1Db21t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UgTPfxXWN/MvUgb87lWfrqPbSM7ooSQGHFe1eP5Wd2g==
21+
-----END CERTIFICATE-----

cmd/certs/CA.srl

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
FDC7B23B140FA79F

0 commit comments

Comments
 (0)