signoz/pkg/signoz/signoz.go
Vibhu Pandey c92ef53e9c
refactor(cache): move to provider pattern (#6837)
### Summary

Move cache to provider pattern
2025-01-17 18:09:39 +05:30

38 lines
732 B
Go

package signoz
import (
"go.signoz.io/signoz/pkg/cache"
"go.signoz.io/signoz/pkg/cache/memorycache"
"go.signoz.io/signoz/pkg/cache/rediscache"
"go.signoz.io/signoz/pkg/config"
"go.signoz.io/signoz/pkg/web"
"go.uber.org/zap"
)
type SigNoz struct {
Cache cache.Cache
Web *web.Web
}
func New(config *config.Config, skipWebFrontend bool) (*SigNoz, error) {
var cache cache.Cache
// init for the cache
switch config.Cache.Provider {
case "memory":
cache = memorycache.New(&config.Cache.Memory)
case "redis":
cache = rediscache.New(&config.Cache.Redis)
}
web, err := web.New(zap.L(), config.Web)
if err != nil && !skipWebFrontend {
return nil, err
}
return &SigNoz{
Cache: cache,
Web: web,
}, nil
}