Backend: Migrate to using non-global configuration (#31856)
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
This commit is contained in:
@@ -69,6 +69,7 @@ func (a *Avatar) Update() (err error) {
|
||||
}
|
||||
|
||||
type CacheServer struct {
|
||||
cfg *setting.Cfg
|
||||
notFound *Avatar
|
||||
cache *gocache.Cache
|
||||
}
|
||||
@@ -109,7 +110,7 @@ func (a *CacheServer) Handler(ctx *models.ReqContext) {
|
||||
|
||||
ctx.Resp.Header().Set("Content-Type", "image/jpeg")
|
||||
|
||||
if !setting.EnableGzip {
|
||||
if !a.cfg.EnableGzip {
|
||||
ctx.Resp.Header().Set("Content-Length", strconv.Itoa(len(avatar.data.Bytes())))
|
||||
}
|
||||
|
||||
@@ -121,21 +122,22 @@ func (a *CacheServer) Handler(ctx *models.ReqContext) {
|
||||
}
|
||||
}
|
||||
|
||||
func NewCacheServer() *CacheServer {
|
||||
func NewCacheServer(cfg *setting.Cfg) *CacheServer {
|
||||
return &CacheServer{
|
||||
notFound: newNotFound(),
|
||||
cfg: cfg,
|
||||
notFound: newNotFound(cfg),
|
||||
cache: gocache.New(time.Hour, time.Hour*2),
|
||||
}
|
||||
}
|
||||
|
||||
func newNotFound() *Avatar {
|
||||
func newNotFound(cfg *setting.Cfg) *Avatar {
|
||||
avatar := &Avatar{notFound: true}
|
||||
|
||||
// load user_profile png into buffer
|
||||
// It's safe to ignore gosec warning G304 since the variable part of the file path comes from a configuration
|
||||
// variable.
|
||||
// nolint:gosec
|
||||
path := filepath.Join(setting.StaticRootPath, "img", "user_profile.png")
|
||||
path := filepath.Join(cfg.StaticRootPath, "img", "user_profile.png")
|
||||
// It's safe to ignore gosec warning G304 since the variable part of the file path comes from a configuration
|
||||
// variable.
|
||||
// nolint:gosec
|
||||
|
||||
Reference in New Issue
Block a user