-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
middleware, renderer and commonly used functions moved to this project
- Loading branch information
Showing
25 changed files
with
605 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,7 +29,7 @@ git remote set-head origin -a | |
|
||
_Note:_ For version `<= 1.4.5`: https://github.com/pilinux/gorest/tree/v1.4.5 | ||
|
||
For new projects, it is recommended to use `v1.5.x` | ||
For new projects, it is recommended to use `>= v1.5.1` | ||
|
||
## Start building | ||
|
||
|
@@ -39,7 +39,7 @@ For new projects, it is recommended to use `v1.5.x` | |
import ( | ||
"github.com/pilinux/gorest/config" | ||
"github.com/pilinux/gorest/database" | ||
"github.com/pilinux/gorestlib/middleware" | ||
"github.com/pilinux/gorest/lib/middleware" | ||
|
||
"github.com/gin-gonic/gin" | ||
) | ||
|
@@ -49,9 +49,19 @@ _Quick tutorial:_ [Wiki][10] + this README.md file | |
|
||
## Updates | ||
|
||
### v1.5.0 [Jul 23 - 2022] | ||
### v1.5.1 [Jul 23 - 2022] | ||
|
||
Link: https://github.com/pilinux/gorest/releases/tag/v1.5.0 | ||
Link: https://github.com/pilinux/gorest/releases/tag/v1.5.1 | ||
|
||
⚡ middleware, renderer and commonly used functions merged here | ||
|
||
After hours of testing, it felt more intuitive | ||
to have all middleware inside `gorest`. | ||
There is no need to import anything from `gorestlib` anymore. | ||
|
||
### v1.5.0 [Jul 23 - 2022] [_Do not use this version_] | ||
|
||
- Release and tag removed from github to avoid import | ||
|
||
⚡ middleware, renderer and commonly used functions moved to a separate repo `github.com/pilinux/gorestlib` | ||
|
||
|
@@ -250,7 +260,26 @@ Accessible endpoints of the test instance: | |
- https://goapi.pilinux.me/api/v1/posts/:id | ||
- https://goapi.pilinux.me/api/v1/hobbies | ||
|
||
To prevent abuse, only HTTP `GET` requests are accepted by the demo server. | ||
To prevent abuse, HTTP `GET` requests are accepted by the demo server. | ||
|
||
Only the following endpoints accept HTTP `POST` requests to test JWT: | ||
|
||
- https://goapi.pilinux.me/api/v1/login | ||
|
||
``` | ||
{ | ||
"Email": "[email protected]", | ||
"Password": "1234.." | ||
} | ||
``` | ||
|
||
- https://goapi.pilinux.me/api/v1/refresh | ||
|
||
``` | ||
{ | ||
"RefreshJWT": "", | ||
} | ||
``` | ||
|
||
<img width="650px" src="https://cdn.pilinux.workers.dev/images/GoREST/screenshot/GoREST.API.Demo.PNG"> | ||
|
||
|
@@ -559,6 +588,7 @@ gorest | |
│---LICENSE | ||
│---CONTRIBUTING.md | ||
│---CODE_OF_CONDUCT.md | ||
│---SECURITY.md | ||
│---.gitattributes | ||
│---.gitignore | ||
│---.env.sample | ||
|
@@ -574,7 +604,7 @@ gorest | |
│ └---server.go | ||
│ └---view.go | ||
│ | ||
│───controller | ||
└───controller | ||
│ └---auth.go | ||
│ └---login.go | ||
│ └---user.go | ||
|
@@ -598,6 +628,21 @@ gorest | |
│ └---hobby.go | ||
│ └---userHobby.go | ||
│ | ||
└───lib | ||
│ └---hashing.go | ||
│ └---validateEmail.go | ||
│ └---removeAllSpace.go | ||
│ │ | ||
│ └───middleware | ||
│ │ └---cors.go | ||
│ │ └---firewall.go | ||
│ │ └---ginpongo2.go | ||
│ │ └---jwt.go | ||
│ │ └---sentry.go | ||
│ │ | ||
│ └───renderer | ||
│ └---render.go | ||
│ | ||
└───logs | ||
│ └---README.md | ||
│ | ||
|
@@ -664,7 +709,7 @@ Default path to the HTML template files: `templates/` | |
### Step 4 | ||
- `middleware`: Import from `github.com/pilinux/gorestlib/middleware` | ||
- `middleware`: All middleware should belong to this package. | ||
### Step 5 (final step) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package lib | ||
|
||
// github.com/pilinux/gorest | ||
// The MIT License (MIT) | ||
// Copyright (c) 2022 pilinux | ||
|
||
import "github.com/alexedwards/argon2id" | ||
|
||
// HashPassConfig - params for argon2id | ||
type HashPassConfig struct { | ||
Memory uint32 | ||
Iterations uint32 | ||
Parallelism uint8 | ||
SaltLength uint32 | ||
KeyLength uint32 | ||
} | ||
|
||
// HashPass - securely hash passwords using Argon2id | ||
func HashPass(config HashPassConfig, pass string) (string, error) { | ||
params := &argon2id.Params{ | ||
Memory: config.Memory * 1024, // the amount of memory used by the Argon2 algorithm (in kibibytes) | ||
Iterations: config.Iterations, // the number of iterations (or passes) over the memory | ||
Parallelism: config.Parallelism, // the number of threads (or lanes) used by the algorithm | ||
SaltLength: config.SaltLength, // length of the random salt. 16 bytes is recommended for password hashing | ||
KeyLength: config.KeyLength, // length of the generated key (or password hash). 16 bytes or more is recommended | ||
} | ||
h, err := argon2id.CreateHash(pass, params) | ||
if err != nil { | ||
return "", err | ||
} | ||
return h, err | ||
} |
Oops, something went wrong.