mirror of
https://github.com/Luzifer/badge-gen.git
synced 2024-09-19 23:32:56 +00:00
add caching to beerpay API
This commit is contained in:
parent
dc36e17aef
commit
4a7e67412c
@ -5,6 +5,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"time"
|
||||||
|
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
"golang.org/x/net/context/ctxhttp"
|
"golang.org/x/net/context/ctxhttp"
|
||||||
@ -30,6 +31,13 @@ func (s beerpayServiceHandler) Handle(ctx context.Context, params []string) (tit
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
title = "beerpay"
|
||||||
|
color = "red"
|
||||||
|
|
||||||
|
cacheKey := fmt.Sprintf("%s::%s", params[0], params[1])
|
||||||
|
text, err = cacheStore.Get("beerpay", cacheKey)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
var resp *http.Response
|
var resp *http.Response
|
||||||
|
|
||||||
apiURL := fmt.Sprintf("https://beerpay.io/api/v1/%s/projects/%s", params[0], params[1])
|
apiURL := fmt.Sprintf("https://beerpay.io/api/v1/%s/projects/%s", params[0], params[1])
|
||||||
@ -46,9 +54,9 @@ func (s beerpayServiceHandler) Handle(ctx context.Context, params []string) (tit
|
|||||||
if err = json.NewDecoder(resp.Body).Decode(&r); err != nil {
|
if err = json.NewDecoder(resp.Body).Decode(&r); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
title = "beerpay"
|
|
||||||
text = fmt.Sprintf("$%d", r.TotalAmount)
|
text = fmt.Sprintf("$%d", r.TotalAmount)
|
||||||
color = "red"
|
cacheStore.Set("beerpay", cacheKey, text, 5*time.Minute)
|
||||||
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user