devtools/{depotview,hackdoc}: tie both together
Change-Id: I0a1ca3b4fa0e0a074eccbe0f8748839b926db9c1
diff --git a/devtools/hackdoc/config/config.go b/devtools/hackdoc/config/config.go
index 70b7b46..aba384b 100644
--- a/devtools/hackdoc/config/config.go
+++ b/devtools/hackdoc/config/config.go
@@ -1,12 +1,12 @@
package config
import (
+ "context"
"fmt"
"html/template"
"strings"
"github.com/BurntSushi/toml"
- "github.com/golang/glog"
"code.hackerspace.pl/hscloud/devtools/hackdoc/source"
)
@@ -73,24 +73,11 @@
return locations
}
-func ForPath(s source.Source, path string) (*Config, error) {
+func ForPath(ctx context.Context, s source.Source, path string) (*Config, error) {
if path != "//" {
path = strings.TrimRight(path, "/")
}
- // Try cache.
- cacheKey := fmt.Sprintf("config:%s", path)
- if v := s.CacheGet(cacheKey); v != nil {
- cfg, ok := v.(*Config)
- if !ok {
- glog.Errorf("Cache key %q corrupted, deleting", cacheKey)
- s.CacheSet([]string{}, cacheKey, nil)
- } else {
- return cfg, nil
- }
- }
-
- // Feed cache.
cfg := &Config{
Templates: make(map[string]*template.Template),
Errors: make(map[string]error),
@@ -98,14 +85,14 @@
tomlPaths := configFileLocations(path)
for _, p := range tomlPaths {
- file, err := s.IsFile(p)
+ file, err := s.IsFile(ctx, p)
if err != nil {
return nil, fmt.Errorf("IsFile(%q): %w", path, err)
}
if !file {
continue
}
- data, err := s.ReadFile(p)
+ data, err := s.ReadFile(ctx, p)
if err != nil {
return nil, fmt.Errorf("ReadFile(%q): %w", path, err)
}
@@ -116,7 +103,7 @@
continue
}
- err = cfg.updateFromToml(p, s, c)
+ err = cfg.updateFromToml(ctx, p, s, c)
if err != nil {
return nil, fmt.Errorf("updating from %q: %w", p, err)
}
@@ -125,7 +112,7 @@
return cfg, nil
}
-func (c *Config) updateFromToml(p string, s source.Source, t *configToml) error {
+func (c *Config) updateFromToml(ctx context.Context, p string, s source.Source, t *configToml) error {
if t.DefaultIndex != nil {
c.DefaultIndex = t.DefaultIndex
}
@@ -134,7 +121,7 @@
tmpl := template.New(k)
for _, source := range v.Sources {
- data, err := s.ReadFile(source)
+ data, err := s.ReadFile(ctx, source)
if err != nil {
c.Errors[p] = fmt.Errorf("reading template file %q: %w", source, err)
return nil