You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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).
13
13
14
14
### Contents
15
15
@@ -24,21 +24,20 @@ WebGo is a minimalistic framework for [Go](https://golang.org) to build web appl
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
31
30
32
31
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)
36
35
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`
39
38
40
39
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.
42
41
43
42
Note: webgo Context is **not** available inside the special handlers (not found & method not implemented)
44
43
@@ -53,9 +52,9 @@ func helloWorld(w http.ResponseWriter, r *http.Request) {
NotFound && NotImplemented are considered `Special` handlers. `webgo.Context(r)` within special handlers will return `nil`.
73
72
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
75
74
76
75
```golang
77
76
funcmain() {
@@ -92,23 +91,23 @@ WebGo provides a few helper functions. When using `Send` or `SendResponse` (othe
92
91
93
92
```json
94
93
{
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>"
97
96
}
98
97
```
99
98
100
99
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.
101
100
102
101
```json
103
102
{
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>"
106
105
}
107
106
```
108
107
109
108
## HTTPS ready
110
109
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.
// Prevent main thread from exiting, and wait for shutdown to complete
189
-
time.Sleep(time.Second * 1)
190
-
}
191
188
}
192
189
```
193
190
@@ -202,9 +199,11 @@ The default logger uses Go standard library's `log.Logger` with `os.Stdout` (for
202
199
## Server-Sent Events
203
200
204
201
[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
+
205
203
## Usage
206
204
207
205
A fully functional sample is provided [here](https://github.com/bnkamalesh/webgo/blob/master/cmd/main.go).
0 commit comments