github.com/cozy/cozy-stack@v0.0.0-20240327093429-939e4a21320e/model/instance/init.go (about) 1 package instance 2 3 import ( 4 "github.com/cozy/cozy-stack/pkg/cache" 5 "github.com/cozy/cozy-stack/pkg/logger" 6 ) 7 8 var service *InstanceService 9 10 // Service handle all the interactions with the "instance" domain. 11 // 12 // This interface has several implementations: 13 // - [InstanceService] with the business logic 14 // - [Mock] with a mock implementation 15 type Service interface { 16 Get(domain string) (*Instance, error) 17 GetWithoutCache(domain string) (*Instance, error) 18 Update(inst *Instance) error 19 Delete(inst *Instance) error 20 CheckPassphrase(inst *Instance, pass []byte) error 21 } 22 23 func Init(c cache.Cache) *InstanceService { 24 service = NewService(c, logger.WithNamespace("instance")) 25 26 return service 27 } 28 29 // Get finds an instance from its domain by using CouchDB or the cache. 30 // 31 // Deprecated: Use [InstanceService.Get] instead. 32 func Get(domain string) (*Instance, error) { 33 return service.Get(domain) 34 } 35 36 // GetFromCouch finds an instance in CouchDB from its domain. 37 // 38 // Deprecated: Use [InstanceService.GetWithoutCache] instead. 39 func GetFromCouch(domain string) (*Instance, error) { 40 return service.GetWithoutCache(domain) 41 } 42 43 // Update saves the changes in CouchDB. 44 // 45 // Deprecated: Use [InstanceService.Update] instead. 46 func Update(inst *Instance) error { 47 return service.Update(inst) 48 } 49 50 // Delete removes the instance document in CouchDB. 51 // 52 // Deprecated: Use [InstanceService.Delete] instead. 53 func Delete(inst *Instance) error { 54 return service.Delete(inst) 55 } 56 57 // CheckPassphrase confirm an instance password 58 // 59 // Deprecated: Use [InstanceService.CheckPassphrase] instead. 60 func CheckPassphrase(inst *Instance, pass []byte) error { 61 return service.CheckPassphrase(inst, pass) 62 }