Skip to content

Commit

Permalink
fix: cache issues
Browse files Browse the repository at this point in the history
Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>
  • Loading branch information
caarlos0 committed Jul 31, 2021
1 parent 28abe99 commit 126d0f6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
4 changes: 2 additions & 2 deletions controller/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (
"github.com/caarlos0/httperr"
)

func Index(fsys fs.FS) http.Handler {
func Index(fsys fs.FS, version string) http.Handler {
return httperr.NewF(func(w http.ResponseWriter, r *http.Request) error {
return executeTemplate(fsys, w, nil)
return executeTemplate(fsys, w, map[string]string{"Version": version})
})
}

Expand Down
7 changes: 5 additions & 2 deletions controller/repositories.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
)

// GetRepo shows the given repo chart.
func GetRepo(fsys fs.FS, github *github.GitHub, cache *cache.Redis) http.Handler {
func GetRepo(fsys fs.FS, github *github.GitHub, cache *cache.Redis, version string) http.Handler {
return httperr.NewF(func(w http.ResponseWriter, r *http.Request) error {
name := fmt.Sprintf(
"%s/%s",
Expand All @@ -29,7 +29,10 @@ func GetRepo(fsys fs.FS, github *github.GitHub, cache *cache.Redis) http.Handler
"Error": err,
})
}
return executeTemplate(fsys, w, details)
return executeTemplate(fsys, w, map[string]interface{}{
"Version": version,
"Details": details,
})
})
}

Expand Down
6 changes: 4 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (
//go:embed static/*
var static embed.FS

var version = "devel"

func main() {
log.SetHandler(text.New(os.Stderr))
// log.SetLevel(log.DebugLevel)
Expand All @@ -40,7 +42,7 @@ func main() {
r := mux.NewRouter()
r.Path("/").
Methods(http.MethodGet).
Handler(controller.Index(static))
Handler(controller.Index(static, version))
r.Path("/").
Methods(http.MethodPost).
HandlerFunc(controller.HandleForm(static))
Expand All @@ -52,7 +54,7 @@ func main() {
Handler(controller.GetRepoChart(github, cache))
r.Path("/{owner}/{repo}").
Methods(http.MethodGet).
Handler(controller.GetRepo(static, github, cache))
Handler(controller.GetRepo(static, github, cache, version))

// generic metrics
requestCounter := promauto.NewCounterVec(prometheus.CounterOpts{
Expand Down

0 comments on commit 126d0f6

Please sign in to comment.