MCPcopy
hub / github.com/ChineseSubFinder/ChineseSubFinder / NewCacheCenter

Function NewCacheCenter

pkg/cache_center/cache_center.go:28–54  ·  view source on GitHub ↗
(cacheName string, Log *logrus.Logger)

Source from the content-addressed store, hash-verified

26}
27
28func NewCacheCenter(cacheName string, Log *logrus.Logger) *CacheCenter {
29
30 c := CacheCenter{}
31 c.Log = Log
32 var err error
33 c.centerFolder, err = pkg.GetRootCacheCenterFolder()
34 if err != nil {
35 panic(err)
36 }
37
38 c.taskQueueSaveRootPath = filepath.Join(c.centerFolder, taskQueueFolderName, cacheName)
39
40 c.downloadFileSaveRootPath = filepath.Join(c.centerFolder, downloadFilesFolderName, cacheName)
41
42 c.dbFPath = filepath.Join(c.centerFolder, cacheName+"_"+dbFileName)
43
44 c.db, err = gorm.Open(sqlite.Open(c.dbFPath), &gorm.Config{})
45 if err != nil {
46 panic(fmt.Sprintf("failed to connect database, %s", err.Error()))
47 }
48 // 迁移 schema
49 err = c.db.AutoMigrate(&models.DailyDownloadInfo{}, &models.TaskQueueInfo{}, &models.DownloadFileInfo{})
50 if err != nil {
51 panic(fmt.Sprintf("db AutoMigrate error, %s", err.Error()))
52 }
53 return &c
54}
55
56func (c *CacheCenter) GetName() string {
57 return c.cacheName

Callers 13

TestNewSupplierFunction · 0.92
defInstanceFunction · 0.92
defInstanceFunction · 0.92
defInstanceFunction · 0.92
defInstanceFunction · 0.92
TestTaskQueue_UpdateFunction · 0.92
mainFunction · 0.92

Calls 1

GetRootCacheCenterFolderFunction · 0.92

Tested by 12

TestNewSupplierFunction · 0.74
defInstanceFunction · 0.74
defInstanceFunction · 0.74
defInstanceFunction · 0.74
defInstanceFunction · 0.74
TestTaskQueue_UpdateFunction · 0.74