-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(chore): retrieve from uuid instead of name to have multiple stor…
…age instances concurrently
- Loading branch information
Showing
53 changed files
with
549 additions
and
393 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
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,139 @@ | ||
package httpcache | ||
|
||
import ( | ||
"fmt" | ||
"strconv" | ||
|
||
"github.com/caddyserver/caddy/v2" | ||
) | ||
|
||
func (s *SouinCaddyMiddleware) parseStorages(ctx caddy.Context) { | ||
if s.Configuration.DefaultCache.Badger.Found { | ||
e := dispatchStorage(ctx, "badger", s.Configuration.DefaultCache.Badger, s.Configuration.DefaultCache.GetStale()) | ||
if e != nil { | ||
s.logger.Sugar().Errorf("Error during Badger init, did you include the Badger storage (--with github.com/darkweak/storages/badger/caddy)? %v", e) | ||
} else { | ||
badger := s.Configuration.DefaultCache.Badger | ||
dir := "" | ||
vdir := "" | ||
if c := badger.Configuration; c != nil { | ||
p, ok := c.(map[string]interface{}) | ||
if ok { | ||
if d, ok := p["Dir"]; ok { | ||
dir = fmt.Sprint(d) | ||
vdir = fmt.Sprint(d) | ||
} | ||
if d, ok := p["ValueDir"]; ok { | ||
vdir = fmt.Sprint(d) | ||
} | ||
} | ||
} | ||
s.Configuration.DefaultCache.Badger.Uuid = fmt.Sprintf( | ||
"BADGER-%s-%s-%s", | ||
dir, | ||
vdir, | ||
s.Configuration.DefaultCache.GetStale(), | ||
) | ||
} | ||
} | ||
if s.Configuration.DefaultCache.Etcd.Found { | ||
e := dispatchStorage(ctx, "etcd", s.Configuration.DefaultCache.Etcd, s.Configuration.DefaultCache.GetStale()) | ||
if e != nil { | ||
s.logger.Sugar().Errorf("Error during Etcd init, did you include the Etcd storage (--with github.com/darkweak/storages/etcd/caddy)? %v", e) | ||
} else { | ||
etcd := s.Configuration.DefaultCache.Etcd | ||
endpoints := etcd.URL | ||
username := "" | ||
password := "" | ||
if c := etcd.Configuration; c != nil { | ||
p, ok := c.(map[string]interface{}) | ||
if ok { | ||
if d, ok := p["Endpoints"]; ok { | ||
endpoints = fmt.Sprint(d) | ||
} | ||
if d, ok := p["Username"]; ok { | ||
username = fmt.Sprint(d) | ||
} | ||
if d, ok := p["Password"]; ok { | ||
password = fmt.Sprint(d) | ||
} | ||
} | ||
} | ||
s.Configuration.DefaultCache.Etcd.Uuid = fmt.Sprintf( | ||
"ETCD-%s-%s-%s-%s", | ||
endpoints, | ||
username, | ||
password, | ||
s.Configuration.DefaultCache.GetStale(), | ||
) | ||
} | ||
} | ||
if s.Configuration.DefaultCache.Nuts.Found { | ||
e := dispatchStorage(ctx, "nuts", s.Configuration.DefaultCache.Nuts, s.Configuration.DefaultCache.GetStale()) | ||
if e != nil { | ||
s.logger.Sugar().Errorf("Error during Nuts init, did you include the Nuts storage (--with github.com/darkweak/storages/nuts/caddy)? %v", e) | ||
} else { | ||
nuts := s.Configuration.DefaultCache.Nuts | ||
dir := "/tmp/souin-nuts" | ||
if c := nuts.Configuration; c != nil { | ||
p, ok := c.(map[string]interface{}) | ||
if ok { | ||
if d, ok := p["Dir"]; ok { | ||
dir = fmt.Sprint(d) | ||
} | ||
} | ||
} else if nuts.Path != "" { | ||
dir = nuts.Path | ||
} | ||
s.Configuration.DefaultCache.Nuts.Uuid = fmt.Sprintf("NUTS-%s-%s", dir, s.Configuration.DefaultCache.GetStale()) | ||
} | ||
} | ||
if s.Configuration.DefaultCache.Olric.Found { | ||
e := dispatchStorage(ctx, "olric", s.Configuration.DefaultCache.Olric, s.Configuration.DefaultCache.GetStale()) | ||
if e != nil { | ||
s.logger.Sugar().Errorf("Error during Olric init, did you include the Olric storage (--with github.com/darkweak/storages/olric/caddy)? %v", e) | ||
} else { | ||
s.Configuration.DefaultCache.Nuts.Uuid = fmt.Sprintf("OLRIC-%s-%s", s.Configuration.DefaultCache.Olric.URL, s.Configuration.DefaultCache.GetStale()) | ||
} | ||
} | ||
if s.Configuration.DefaultCache.Otter.Found { | ||
e := dispatchStorage(ctx, "otter", s.Configuration.DefaultCache.Otter, s.Configuration.DefaultCache.GetStale()) | ||
if e != nil { | ||
s.logger.Sugar().Errorf("Error during Otter init, did you include the Otter storage (--with github.com/darkweak/storages/otter/caddy)? %v", e) | ||
} else { | ||
s.Configuration.DefaultCache.Otter.Uuid = fmt.Sprintf("OTTER-%s", s.Configuration.DefaultCache.GetStale()) | ||
} | ||
} | ||
if s.Configuration.DefaultCache.Redis.Found { | ||
e := dispatchStorage(ctx, "redis", s.Configuration.DefaultCache.Redis, s.Configuration.DefaultCache.GetStale()) | ||
if e != nil { | ||
s.logger.Sugar().Errorf("Error during Redis init, did you include the Redis storage (--with github.com/darkweak/storages/redis/caddy)? %v", e) | ||
} else { | ||
redis := s.Configuration.DefaultCache.Redis | ||
address := redis.URL | ||
dbname := 0 | ||
cname := "souin-redis" | ||
if c := redis.Configuration; c != nil { | ||
p, ok := c.(map[string]interface{}) | ||
if ok { | ||
if d, ok := p["ClientName"]; ok { | ||
cname = fmt.Sprint(d) | ||
} | ||
if d, ok := p["InitAddress"]; ok { | ||
address = fmt.Sprint(d) | ||
} | ||
if d, ok := p["SelectDB"]; ok { | ||
dbname, _ = strconv.Atoi(fmt.Sprint(d)) | ||
} | ||
} | ||
} | ||
s.Configuration.DefaultCache.Redis.Uuid = fmt.Sprintf( | ||
"REDIS-%s-%d-%s-%s", | ||
address, | ||
dbname, | ||
cname, | ||
s.Configuration.DefaultCache.GetStale(), | ||
) | ||
} | ||
} | ||
} |
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
Oops, something went wrong.