perkeep/lib/go/client/client.go

48 lines
971 B
Go
Raw Normal View History

package client
import (
"fmt"
"sync"
)
type Stats struct {
// The number of uploads that were requested, but perhaps
// not actually performed if the server already had the items.
UploadRequests ByCountAndBytes
// The uploads which were actually sent to the blobserver
// due to the server not having the blobs
Uploads ByCountAndBytes
}
func (s *Stats) String() string {
return "[uploadRequests=" + s.UploadRequests.String() + " uploads=" + s.Uploads.String() + "]"
}
type Client struct {
server string
password string
statsMutex sync.Mutex
stats Stats
}
type ByCountAndBytes struct {
Blobs int
Bytes int64
}
func (bb *ByCountAndBytes) String() string {
return fmt.Sprintf("[blobs=%d bytes=%d]", bb.Blobs, bb.Bytes)
}
func NewOrFail() *Client {
return &Client{server: blobServerOrDie(), password: passwordOrDie()}
}
func (c *Client) Stats() Stats {
c.statsMutex.Lock()
defer c.statsMutex.Unlock()
return c.stats // copy
}