Skip to content

Commit 0edba4d

Browse files
authored
fix: Documentation and linter (#39)
[*] Update README [*] Tell that the distributed cache is supported in full version [*] Fix linter errors
1 parent 728a505 commit 0edba4d

6 files changed

Lines changed: 27 additions & 13 deletions

File tree

README.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ As it's written in go, it can be deployed on any server and thanks to the docker
2929
It's RFC compatible, supporting Vary, request coalescing and other specifications related to the [RFC-7234](https://tools.ietf.org/html/rfc7234)
3030

3131
## Disclaimer
32-
If you need redis or other custom cache providers, you have to use the full-featured version. You can read the documentation, on [the full-featured branch](https://github.com/Darkweak/Souin/tree/full-version) to discover the specific parts.
32+
If you need redis, olric or other custom cache providers, you have to use the full-featured version. You can read the documentation, on [the full-featured branch](https://github.com/Darkweak/Souin/tree/full-version) to discover the specific parts.
3333

3434
## Configuration
3535
The configuration file is stored at `/anywhere/configuration.yml`. You can edit it provided you fill at least the required parameters as shown below.
@@ -135,9 +135,14 @@ See the sequence for the minimal version below
135135
<img src="docs/plantUML/sequenceDiagram.svg?sanitize=true" alt="Sequence diagram">
136136

137137
## Cache systems
138-
The cache system sits on top of two providers at the moment. It provides an in-memory and redis cache systems because setting, getting, updating and deleting keys in Redis is as easy as it gets.
139-
In order to do that, Redis needs to be either on the same network as the Souin instance when using docker-compose or over the internet, then it will use by default in-memory to avoid network latency as much as possible.
140-
Souin will return at first the in-memory response when it gives a non-empty response, then the redis one will be used with same condition, or fallback to the reverse proxy otherwise.
138+
Supported providers
139+
- [Redis](https://github.com/go-redis/redis)
140+
- [Olric](https://github.com/buraksezer/olric)
141+
142+
The cache system sits on top of three providers at the moment. It provides an in-memory, redis and Olric cache systems because setting, getting, updating and deleting keys in these providers is as easy as it gets.
143+
In order to do that, Redis and Olric providers need to be either on the same network as the Souin instance when using docker-compose or over the internet, then it will use by default in-memory to avoid network latency as much as possible.
144+
Souin will return at first the in-memory response when it gives a non-empty response, then the olric followed by the redis one with same condition, or fallback to the reverse proxy otherwise.
145+
Since 1.4.2, Souin supports [Olric](https://github.com/buraksezer/olric) to handle distributed cache.
141146

142147
### Cache invalidation
143148
The cache invalidation is build for CRUD requests, if you're doing a GET HTTP request, it will serve the cached response when it exists, otherwise the reverse-proxy response will be served.
@@ -238,3 +243,4 @@ Thanks to these users for contributing or helping this project in any way
238243
* [Deuchnord](https://github.com/deuchnord)
239244
* [Sata51](https://github.com/sata51)
240245
* [Pierre Diancourt](https://github.com/pierrediancourt)
246+
* [Burak Sezer](https://github.com/buraksezer)

api/auth/jwt.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import (
77
"time"
88
)
99

10-
type jwtProvider struct {
10+
// JwtProvider is the representation of decoded JWT
11+
type JwtProvider struct {
1112
Username string `json:"username"`
1213
jwt.StandardClaims
1314
}
@@ -43,7 +44,7 @@ func signJWT(security *SecurityAPI, w http.ResponseWriter, r *http.Request) {
4344
}
4445

4546
// Create the JWT claims, which includes the username and expiry time
46-
claims := &jwtProvider{
47+
claims := &JwtProvider{
4748
Username: creds.Username,
4849
StandardClaims: jwt.StandardClaims{},
4950
}
@@ -69,7 +70,7 @@ func refresh(security *SecurityAPI, w http.ResponseWriter, r *http.Request) {
6970
}
7071

7172
// CheckToken will return if token is valid or not
72-
func CheckToken(security *SecurityAPI, w http.ResponseWriter, r *http.Request) (*jwtProvider, error) {
73+
func CheckToken(security *SecurityAPI, w http.ResponseWriter, r *http.Request) (*JwtProvider, error) {
7374
c, err := r.Cookie(tokenName)
7475
if err != nil {
7576
if err.Error() == http.ErrNoCookie.Error() {
@@ -80,7 +81,7 @@ func CheckToken(security *SecurityAPI, w http.ResponseWriter, r *http.Request) (
8081
return nil, &tokenError{found: true}
8182
}
8283
tknStr := c.Value
83-
claims := &jwtProvider{}
84+
claims := &JwtProvider{}
8485
tkn, err := jwt.ParseWithClaims(tknStr, claims, func(token *jwt.Token) (interface{}, error) {
8586
return security.secret, nil
8687
})
@@ -100,7 +101,7 @@ func CheckToken(security *SecurityAPI, w http.ResponseWriter, r *http.Request) (
100101
return claims, nil
101102
}
102103

103-
func setCookie(w http.ResponseWriter, claims *jwtProvider, secret []byte) {
104+
func setCookie(w http.ResponseWriter, claims *JwtProvider, secret []byte) {
104105
expirationTime := time.Now().Add(lifetime)
105106
claims.ExpiresAt = expirationTime.Unix()
106107
token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)

api/auth/security.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ type SecurityAPI struct {
1515
users map[string]string
1616
}
1717

18+
// InitializeSecurity initialize the security endpoints
1819
func InitializeSecurity(configuration configurationtypes.AbstractConfigurationInterface) *SecurityAPI {
1920
basePath := configuration.GetAPI().Security.BasePath
2021
enabled := configuration.GetAPI().Security.Enable

cache/keysaver/keySaver.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ import (
77
"time"
88
)
99

10+
// ADD to add
1011
const ADD = "add"
12+
13+
// DELETE to delete
1114
const DELETE = "delete"
1215

1316
type payload struct {

configurationtypes/types.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,20 @@ type DefaultCache struct {
4141
type APIEndpoint struct {
4242
BasePath string `yaml:"basepath"`
4343
Enable bool `yaml:"enable"`
44-
Security bool `yaml:"security"`
44+
Security bool `yaml:"security"`
4545
}
4646

47+
// User is the minimal structure to define a user
4748
type User struct {
4849
Username string `yaml:"username"`
4950
Password string `yaml:"password"`
5051
}
5152

5253
// SecurityAPI object contains informations related to the endpoints
5354
type SecurityAPI struct {
54-
BasePath string `yaml:"basepath"`
55-
Enable bool `yaml:"enable"`
56-
Secret string `yaml:"secret"`
55+
BasePath string `yaml:"basepath"`
56+
Enable bool `yaml:"enable"`
57+
Secret string `yaml:"secret"`
5758
Users []User `yaml:"users"`
5859
}
5960

tests/mock.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,12 @@ func MockInitializeRegexp(configurationInstance configurationtypes.AbstractConfi
6969
return *regexp.MustCompile(u)
7070
}
7171

72+
// GetTokenName returns the token name
7273
func GetTokenName() string {
7374
return "souin-authorization-token"
7475
}
7576

77+
// GetValidToken returns a valid token
7678
func GetValidToken() *http.Cookie {
7779
return &http.Cookie{
7880
Name: GetTokenName(),

0 commit comments

Comments
 (0)