diff options
author | Julien Dessaux | 2024-09-04 09:11:35 +0200 |
---|---|---|
committer | Julien Dessaux | 2024-09-04 09:11:35 +0200 |
commit | 00cb3a2488db11c8ce96d182915b8c448edce976 (patch) | |
tree | 80d46044e4cdd17c2da324527596e34359a03603 /stdlib/backups | |
parent | feat(stdlib): added a basic borg client custom promise (diff) | |
download | gonf-00cb3a2488db11c8ce96d182915b8c448edce976.tar.gz gonf-00cb3a2488db11c8ce96d182915b8c448edce976.tar.bz2 gonf-00cb3a2488db11c8ce96d182915b8c448edce976.zip |
chore(gonf): add a DECLARED promise status and make it the default instead of PROMISED
Diffstat (limited to 'stdlib/backups')
-rw-r--r-- | stdlib/backups/borg/client.go | 20 | ||||
-rw-r--r-- | stdlib/backups/borg/server.go | 22 |
2 files changed, 29 insertions, 13 deletions
diff --git a/stdlib/backups/borg/client.go b/stdlib/backups/borg/client.go index a203ae2..95d8d0d 100644 --- a/stdlib/backups/borg/client.go +++ b/stdlib/backups/borg/client.go @@ -33,13 +33,18 @@ type BorgClient struct { status gonf.Status } +var borgClient *BorgClient = nil + func (b *BorgClient) IfRepaired(p ...gonf.Promise) gonf.Promise { b.chain = append(b.chain, p...) return b } func (b *BorgClient) Promise() *BorgClient { - gonf.MakeCustomPromise(b).Promise() + if b.status == gonf.DECLARED { + b.status = gonf.PROMISED + gonf.MakeCustomPromise(b).Promise() + } return b } @@ -101,12 +106,15 @@ func (b BorgClient) Status() gonf.Status { } func Client() *BorgClient { - return &BorgClient{ - chain: nil, - jobs: make(map[string]*Job), - path: "/etc/borg/", - status: gonf.PROMISED, + if borgClient == nil { + borgClient = &BorgClient{ + chain: nil, + jobs: make(map[string]*Job), + path: "/etc/borg/", + status: gonf.DECLARED, + } } + return borgClient } func (b *BorgClient) Add(name string, path string, privateKey []byte, hostname string) *BorgClient { diff --git a/stdlib/backups/borg/server.go b/stdlib/backups/borg/server.go index 4fe0e74..29794d8 100644 --- a/stdlib/backups/borg/server.go +++ b/stdlib/backups/borg/server.go @@ -15,13 +15,18 @@ type BorgServer struct { status gonf.Status } +var borgServer *BorgServer = nil + func (b *BorgServer) IfRepaired(p ...gonf.Promise) gonf.Promise { b.chain = append(b.chain, p...) return b } func (b *BorgServer) Promise() *BorgServer { - gonf.MakeCustomPromise(b).Promise() + if b.status == gonf.DECLARED { + b.status = gonf.PROMISED + gonf.MakeCustomPromise(b).Promise() + } return b } @@ -80,13 +85,16 @@ func (b BorgServer) Status() gonf.Status { } func Server() *BorgServer { - return &BorgServer{ - chain: nil, - clients: make(map[string][]byte), - path: "/srv/borg/", - user: "borg", - status: gonf.PROMISED, + if borgServer == nil { + borgServer = &BorgServer{ + chain: nil, + clients: make(map[string][]byte), + path: "/srv/borg/", + user: "borg", + status: gonf.DECLARED, + } } + return borgServer } func (b *BorgServer) Add(name string, publicKey []byte) *BorgServer { |