File tree Expand file tree Collapse file tree 3 files changed +56
-0
lines changed
Expand file tree Collapse file tree 3 files changed +56
-0
lines changed Original file line number Diff line number Diff line change @@ -9,4 +9,10 @@ require (
99<%- if eq (index .Params ` billingEnabled` ) "yes" %>
1010 github.com/stripe/stripe-go/v72 v72.43.0
1111<%- end %>
12+ <%- if eq (index .Params `cacheStore`) "redis" %>
13+ github.com/go-redis/redis/v8 v8.11.4
14+ <%- end %>
15+ <%- if eq (index .Params `cacheStore`) "memcached" %>
16+ github.com/bradfitz/gomemcache/memcache v0.0.0-20190913173617-a41fca850d0b
17+ <%- end %>
1218)
Original file line number Diff line number Diff line change 1+ package cachestore
2+
3+ import (
4+ "os"
5+ "fmt"
6+ < % if eq (index .Params `cachestore` ) "redis" % >
7+ "context"
8+ "github.com/go-redis/redis/v8"
9+ < % end % >
10+ < % if eq (index .Params `cachestore` ) "memcached" % >
11+ "github.com/bradfitz/gomemcache/memcache"
12+ < % end % >
13+ )
14+
15+ var cacheEndpoint = os .Getenv ("CACHE_ENDPOINT" )
16+ var cachePort = os .Getenv ("CACHE_PORT" )
17+
18+ < % if eq (index .Params `cachestore` ) "redis" % >
19+ func TestConnection () {
20+ context := context .Background ()
21+ rdb := redis .NewClient (& redis.Options {
22+ Addr : fmt .Sprintf ("%s:%s" , cacheEndpoint , cachePort ),
23+ Password : "" , // no password set
24+ DB : 0 , // use default DB
25+ })
26+
27+ err := rdb .Set (ctx , "cache-test" , "value" , 0 ).Err ()
28+ if err != nil {
29+ panic (err )
30+ }
31+ }
32+ < % end % >
33+
34+ < % if eq (index .Params `cachestore` ) "memcached" % >
35+ func TestConnection () {
36+ mc := memcache .New (fmt .Sprintf ("%s:%s" , cacheEndpoint , cachePort ))
37+ err := mc .Set (& memcache.Item {Key : "cache-test" , Value : []byte ("value" )})
38+ if err != nil {
39+ panic (err )
40+ }
41+ }
42+ < % end % >
Original file line number Diff line number Diff line change @@ -24,6 +24,9 @@ import (
2424< % if eq (index .Params `billingEnabled` ) "yes" % >
2525 "<% .Files.Repository %>/internal/billing"
2626< % - end % >
27+ < % if neq (index .Params `cachestore` ) "none" % >
28+ "<% .Files.Repository %>/internal/cachestore"
29+ < % end % >
2730)
2831
2932const gracefulShutdownTimeout = 10 * time .Second
@@ -35,6 +38,11 @@ func main() {
3538 db := database .Connect ()
3639 db .TestConnection ()
3740
41+ < % if neq (index .Params `cachestore` ) "none" % >
42+ // test cacheStore connection
43+ cachestore .TestConnection ()
44+ < % end % >
45+
3846 r := http .NewServeMux ()
3947 r .HandleFunc ("/status/ready" , readinessCheckEndpoint )
4048
You can’t perform that action at this time.
0 commit comments