Skip to content

Commit c590e63

Browse files
Merge pull request #70 from System-Glitch/develop
v2.10.0
2 parents 91295e4 + a768203 commit c590e63

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+1280
-954
lines changed

β€ŽREADME.mdβ€Ž

Lines changed: 49 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
<h2 align="center">An Elegant Golang Web Framework</h2>
1515

16-
Goyave is a progressive and accessible web application framework, aimed at making development easy and enjoyable. It has a philosophy of cleanliness and conciseness to make programs more elegant, easier to maintain and more focused.
16+
Goyave is a progressive and accessible web application framework focused on APIs, aimed at making development easy and enjoyable. It has a philosophy of cleanliness and conciseness to make programs more elegant, easier to maintain and more focused.
1717

1818
<table>
1919
<tr>
@@ -32,7 +32,7 @@ Goyave is a progressive and accessible web application framework, aimed at makin
3232
</tr>
3333
</table>
3434

35-
Most golang frameworks for web development don't have a strong directory structure nor conventions to make applications have a uniform architecture and limit redundancy. This makes it difficult to work with them on different projects. In companies, having a well-defined and documented architecture helps new developers integrate projects faster, and reduces the time needed for maintaining them. For open source projects, it helps newcomers understanding the project and makes it easier to contribute.
35+
Most golang frameworks for web development don't have a strong directory structure nor conventions to make applications have a uniform architecture and limit redundancy. This makes it difficult to work with them on different projects. In companies, having a well-defined and documented architecture helps new developers integrate projects faster, and reduces the time needed for maintaining them. For open source projects, it helps newcomers understanding the project and makes it easier to contribute. With Goyave, expect a full package with minimum setup.
3636

3737
## Table of contents
3838

@@ -102,6 +102,7 @@ This section's goal is to give a **brief** look at the main features of the fram
102102
- [Testing](#testing)
103103
- [Status handlers](#status-handlers)
104104
- [CORS](#cors)
105+
- [Authentication](#authentication)
105106

106107
### Hello world from scratch
107108

@@ -111,7 +112,7 @@ The example below shows a basic `Hello world` application using Goyave.
111112
import "github.com/System-Glitch/goyave/v2"
112113

113114
func registerRoutes(router *goyave.Router) {
114-
router.Route("GET", "/hello", func(response *goyave.Response, request *goyave.Request) {
115+
router.Get("/hello", func(response *goyave.Response, request *goyave.Request) {
115116
response.String(http.StatusOK, "Hello world!")
116117
}, nil)
117118
}
@@ -178,18 +179,18 @@ func Register(router *goyave.Router) {
178179
// Register your routes here
179180

180181
// With closure, not recommended
181-
router.Route("GET", "/hello", func(response *goyave.Response, r *goyave.Request) {
182+
router.Get("GET", "/hello", func(response *goyave.Response, r *goyave.Request) {
182183
response.String(http.StatusOK, "Hi!")
183184
}, nil)
184185

185-
router.Route("GET", "/hello", myHandlerFunction, nil)
186-
router.Route("POST", "/user", user.Register, userrequest.Register)
186+
router.Get("/hello", myHandlerFunction, nil)
187+
router.Post("/user", user.Register, userrequest.Register)
187188
router.Route("PUT|PATCH", "/user", user.Update, userrequest.Update)
188189
router.Route("POST", "/product", product.Store, productrequest.Store, middleware.Trim)
189190
}
190191
```
191192

192-
**Method signature:**
193+
**`Route` Method signature:**
193194

194195
| Parameters | Return |
195196
|--------------------------------------|-----------------|
@@ -204,9 +205,9 @@ URIs can have parameters, defined using the format `{name}` or `{name:pattern}`.
204205

205206
**Example:**
206207
``` go
207-
router.Route("GET", "/product/{key}", product.Show, nil)
208-
router.Route("GET", "/product/{id:[0-9]+}", product.ShowById, nil)
209-
router.Route("GET", "/category/{category}/{id:[0-9]+}", category.Show, nil)
208+
router.Get("/product/{key}", product.Show, nil)
209+
router.Get("/product/{id:[0-9]+}", product.ShowById, nil)
210+
router.Get("/category/{category}/{id:[0-9]+}", category.Show, nil)
210211
```
211212

212213
Route parameters can be retrieved as a `map[string]string` in handlers using the request's `Params` attribute.
@@ -339,7 +340,7 @@ var (
339340
Once your rules sets are defined, you need to assign them to your routes. The rule set for a route is the last parameter of the route definition.
340341

341342
``` go
342-
router.Route("POST", "/product", product.Store, productrequest.Store)
343+
router.Post("/product", product.Store, productrequest.Store)
343344
```
344345

345346

@@ -596,6 +597,43 @@ router.CORS(options)
596597

597598
**Learn more about CORS in the [documentation](https://system-glitch.github.io/goyave/guide/advanced/cors.html).**
598599

600+
### Authentication
601+
602+
Goyave provides a convenient and expandable way of handling authentication in your application. Authentication can be enabled when registering your routes:
603+
604+
``` go
605+
import "github.com/System-Glitch/goyave/v2/auth"
606+
607+
//...
608+
609+
authenticator := auth.Middleware(&model.User{}, &auth.BasicAuthenticator{})
610+
router.Middleware(authenticator)
611+
```
612+
613+
Authentication is handled by a simple middleware calling an **Authenticator**. This middleware also needs a model, which will be used to fetch user information on a successful login.
614+
615+
Authenticators use their model's struct fields tags to know which field to use for username and password. To make your model compatible with authentication, you must add the `auth:"username"` and `auth:"password"` tags:
616+
617+
``` go
618+
type User struct {
619+
gorm.Model
620+
Email string `gorm:"type:varchar(100);unique_index" auth:"username"`
621+
Name string `gorm:"type:varchar(100)"`
622+
Password string `gorm:"type:varchar(60)" auth:"password"`
623+
}
624+
```
625+
626+
When a user is successfully authenticated on a protected route, its information is available in the controller handler, through the request `User` field.
627+
628+
``` go
629+
func Hello(response *goyave.Response, request *goyave.Request) {
630+
user := request.User.(*model.User)
631+
response.String(http.StatusOK, "Hello " + user.Name)
632+
}
633+
```
634+
635+
**Learn more about authentication in the [documentation](https://system-glitch.github.io/goyave/guide/advanced/authentication.html).**
636+
599637
## Contributing
600638

601639
Thank you for considering contributing to the Goyave framework! You can find the contribution guide in the [documentation](https://system-glitch.github.io/goyave/guide/contribution-guide.html).

β€Ždocs/404.htmlβ€Ž

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<!DOCTYPE html>
2+
<html lang="en-US">
3+
<head>
4+
<meta charset="utf-8">
5+
<meta name="viewport" content="width=device-width,initial-scale=1">
6+
<title>Goyave</title>
7+
<meta name="generator" content="VuePress 1.4.1">
8+
<link rel="icon" type="image/png" sizes="16x16" href="/goyave/goyave_16.png">
9+
<link rel="icon" type="image/png" sizes="32x32" href="/goyave/goyave_32.png">
10+
<link rel="icon" type="image/png" sizes="64x64" href="/goyave/goyave_64.png">
11+
<link rel="icon" type="image/png" sizes="128x128" href="/goyave/goyave_128.png">
12+
<link rel="icon" type="image/png" sizes="256x256" href="/goyave/goyave_256.png">
13+
<link rel="icon" type="image/png" sizes="512x512" href="/goyave/goyave_512.png">
14+
<meta name="description" content="An Elegant Golang Web Framework">
15+
<meta property="twitter:title" content="Goyave">
16+
<meta property="twitter:description" content="An Elegant Golang Web Framework">
17+
<meta property="twitter:image:src" content="https://system-glitch.github.io/goyave/goyave_banner.png">
18+
<meta property="twitter:card" content="summary_large_image">
19+
<meta property="og:title" content="Goyave">
20+
<meta property="og:type" content="website">
21+
<meta property="og:description" content="An Elegant Golang Web Framework">
22+
<meta property="og:image" content="https://system-glitch.github.io/goyave/goyave_banner.png">
23+
<meta property="og:site_name" content="Goyave">
24+
<link rel="preload" href="/goyave/assets/css/0.styles.ae034a9f.css" as="style"><link rel="preload" href="/goyave/assets/js/app.ac32b3e6.js" as="script"><link rel="preload" href="/goyave/assets/js/4.f15bace1.js" as="script"><link rel="prefetch" href="/goyave/assets/js/10.97a5cc72.js"><link rel="prefetch" href="/goyave/assets/js/11.9bb90619.js"><link rel="prefetch" href="/goyave/assets/js/12.ee233449.js"><link rel="prefetch" href="/goyave/assets/js/13.9051c40a.js"><link rel="prefetch" href="/goyave/assets/js/14.1d0f4b69.js"><link rel="prefetch" href="/goyave/assets/js/15.aaf8265c.js"><link rel="prefetch" href="/goyave/assets/js/16.389b72fd.js"><link rel="prefetch" href="/goyave/assets/js/17.f30b8f75.js"><link rel="prefetch" href="/goyave/assets/js/18.d515c312.js"><link rel="prefetch" href="/goyave/assets/js/19.65053d4b.js"><link rel="prefetch" href="/goyave/assets/js/2.68c0af99.js"><link rel="prefetch" href="/goyave/assets/js/20.f033d601.js"><link rel="prefetch" href="/goyave/assets/js/21.9fff9bda.js"><link rel="prefetch" href="/goyave/assets/js/22.fb2c838d.js"><link rel="prefetch" href="/goyave/assets/js/23.35bd4881.js"><link rel="prefetch" href="/goyave/assets/js/24.a44a1d89.js"><link rel="prefetch" href="/goyave/assets/js/25.e1f32d08.js"><link rel="prefetch" href="/goyave/assets/js/26.02bdf651.js"><link rel="prefetch" href="/goyave/assets/js/27.8239d5ce.js"><link rel="prefetch" href="/goyave/assets/js/28.0e69ec47.js"><link rel="prefetch" href="/goyave/assets/js/29.b6d2bc3c.js"><link rel="prefetch" href="/goyave/assets/js/3.a002ba5f.js"><link rel="prefetch" href="/goyave/assets/js/30.d039792e.js"><link rel="prefetch" href="/goyave/assets/js/5.c89dd554.js"><link rel="prefetch" href="/goyave/assets/js/6.4e229a0d.js"><link rel="prefetch" href="/goyave/assets/js/7.1461637f.js"><link rel="prefetch" href="/goyave/assets/js/8.20e04508.js"><link rel="prefetch" href="/goyave/assets/js/9.61891602.js">
25+
<link rel="stylesheet" href="/goyave/assets/css/0.styles.ae034a9f.css">
26+
</head>
27+
<body>
28+
<div id="app" data-server-rendered="true"><div class="theme-container"><div class="theme-default-content"><h1>404</h1> <blockquote>That's a Four-Oh-Four.</blockquote> <a href="/goyave/" class="router-link-active">
29+
Take me home.
30+
</a></div></div><div class="global-ui"><!----></div></div>
31+
<script src="/goyave/assets/js/app.ac32b3e6.js" defer></script><script src="/goyave/assets/js/4.f15bace1.js" defer></script>
32+
</body>
33+
</html>

β€Ždocs/assets/css/0.styles.27b9d501.cssβ€Ž

Lines changed: 0 additions & 1 deletion
This file was deleted.

β€Ždocs/assets/css/0.styles.ae034a9f.cssβ€Ž

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

β€Ždocs/assets/js/10.8f216a3d.jsβ€Ž renamed to β€Ždocs/assets/js/10.97a5cc72.jsβ€Ž

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

β€Ždocs/assets/js/11.14610090.jsβ€Ž

Lines changed: 0 additions & 1 deletion
This file was deleted.

β€Ždocs/assets/js/11.9bb90619.jsβ€Ž

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

β€Ždocs/assets/js/12.89b3bc7b.jsβ€Ž renamed to β€Ždocs/assets/js/12.ee233449.jsβ€Ž

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
Β (0)