Files
trivy/internal/config/cache.go
Teppei Fukuda 7b86f81e29 feat(cache): support Redis (#770)
* feat(config): add --cache-backend

* feat(operation): embed cache.Cache into operation.Cache

* feat(cache): support redis://

* test(integration): add redis test

* chore(README): add --cache-backend

* chore(mod): update

* chore: add disclaimer
2020-12-21 08:26:19 +02:00

32 lines
718 B
Go

package config
import (
"strings"
"github.com/urfave/cli/v2"
"golang.org/x/xerrors"
)
// CacheConfig holds the config for cache
type CacheConfig struct {
CacheBackend string
}
// NewCacheConfig returns an instance of CacheConfig
func NewCacheConfig(c *cli.Context) CacheConfig {
return CacheConfig{
CacheBackend: c.String("cache-backend"),
}
}
// Init initialize the CacheConfig
func (c *CacheConfig) Init() error {
// "redis://" or "fs" are allowed for now
// An empty value is also allowed for testability
if !strings.HasPrefix(c.CacheBackend, "redis://") &&
c.CacheBackend != "fs" && c.CacheBackend != "" {
return xerrors.Errorf("unsupported cache backend: %s", c.CacheBackend)
}
return nil
}