envoy: refactor controlplane xds to new envoyconfig package (#2086)

This commit is contained in:
Caleb Doxsey 2021-04-13 13:51:44 -06:00 committed by GitHub
parent 0e66619081
commit 1dcccf2b56
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 421 additions and 378 deletions

View file

@ -0,0 +1,35 @@
package filemgr
import (
"os"
"path/filepath"
"github.com/google/uuid"
)
type config struct {
cacheDir string
}
// An Option updates the config.
type Option = func(*config)
// WithCacheDir returns an Option that sets the cache dir.
func WithCacheDir(cacheDir string) Option {
return func(cfg *config) {
cfg.cacheDir = cacheDir
}
}
func newConfig(options ...Option) *config {
cfg := new(config)
cacheDir, err := os.UserCacheDir()
if err != nil {
cacheDir = filepath.Join(os.TempDir(), uuid.New().String())
}
WithCacheDir(filepath.Join(cacheDir, "pomerium", "envoy", "files"))(cfg)
for _, o := range options {
o(cfg)
}
return cfg
}