Files

48 lines
1.4 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Package impl 提供CMS服务的实现层
// 负责初始化和管理各种外部服务的连接包括数据库、缓存、etcd等
package impl
import (
"bsm/full/module/base/cms/internal/config"
"git.apinb.com/bsm-sdk/core/cache/redis"
"git.apinb.com/bsm-sdk/core/with"
cache "github.com/patrickmn/go-cache"
clientv3 "go.etcd.io/etcd/client/v3"
"gorm.io/gorm"
)
var (
// RedisService Redis缓存服务客户端
// 用于存储临时数据和缓存热点数据
RedisService *redis.RedisClient
// EtcdService Etcd客户端
// 用于服务发现和配置管理
EtcdService *clientv3.Client
// DBService 数据库服务连接
// 用于数据持久化存储
DBService *gorm.DB
// MemoryService 内存缓存服务
// 用于存储频繁访问的数据,提供最快的访问速度
MemoryService *cache.Cache
)
// NewImpl 初始化实现层
// 建立与各种外部服务的连接包括内存缓存、Redis、数据库和Etcd
// 这些连接将在整个服务生命周期中使用
func NewImpl() {
// 初始化内存缓存服务,用于存储热点数据
MemoryService = with.Memory(nil)
// 初始化Redis缓存服务用于分布式缓存
RedisService = with.RedisCache(config.Spec.Cache)
// 初始化数据库连接,用于数据持久化
DBService = with.Databases(config.Spec.Databases, nil)
// 初始化Etcd客户端用于服务发现和配置管理
EtcdService = with.Etcd(config.Spec.Etcd)
}