From 00cb3a2488db11c8ce96d182915b8c448edce976 Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Wed, 4 Sep 2024 09:11:35 +0200 Subject: chore(gonf): add a DECLARED promise status and make it the default instead of PROMISED --- stdlib/backups/borg/server.go | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'stdlib/backups/borg/server.go') 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 { -- cgit v1.2.3