Documentation ¶
Index ¶
- type Stats
- func (s *Stats) AddBytes(cnt int64)
- func (s *Stats) AddLine()
- func (s Stats) Clone() Stats
- func (s Stats) InfoString() string
- func (s Stats) JSONBytes() []byte
- func (s Stats) JSONString() string
- func (s *Stats) ParseCreated() time.Time
- func (s Stats) ParsePath() (scheme, host, fPth string)
- func (s *Stats) SetChecksum(hsh hash.Hash)
- func (s *Stats) SetCreated(t time.Time)
- func (s *Stats) SetPath(pth string)
- func (s *Stats) SetSize(size int64)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Stats ¶
type Stats struct { // LineCnt returns the file line count. LineCnt int64 `json:"linecnt" uri:"linecnt"` // ByteCount returns uncompressed raw file byte count. ByteCnt int64 `json:"bytecnt" uri:"bytecnt"` // Size holds the actual file size. Size int64 `json:"size" uri:"size"` // Checksum returns the base64 encoded string of the file md5 hash. Checksum string `json:"checksum" uri:"checksum"` // Path returns the full absolute path of the file. Path string `json:"path" uri:"origin"` // Created returns the date the file was created or last updated; // whichever is more recent. Created string `json:"created" uri:"created"` IsDir bool `json:"-"` // contains filtered or unexported fields }
func New ¶
func New() Stats
Example ¶
sts := New() fmt.Println(sts.LineCnt) // output: 0 fmt.Println(sts.ByteCnt) // output: 0 fmt.Println(sts.Size) // output: 0 fmt.Println(sts.Checksum) // output: fmt.Println(sts.Path) // output: fmt.Println(sts.Created) // output:
Output: 0 0 0
func NewFromBytes ¶
NewFromBytes creates Stats from json bytes.
Example ¶
sts := NewFromBytes([]byte(`{"linecnt":10,"bytecnt":100,"size":200,"checksum":"test checksum","path":"test path","created":"test created"}`)) fmt.Println(sts.LineCnt) // output: 10 fmt.Println(sts.ByteCnt) // output: 100 fmt.Println(sts.Size) // output: 200 fmt.Println(sts.Checksum) // output: test checksum fmt.Println(sts.Path) // output: test path fmt.Println(sts.Created) // output: test created
Output: 10 100 200 test checksum test path test created
func NewFromInfo ¶
NewFromInfo creates Stats from a uri formatted info string.
func (*Stats) AddLine ¶
func (s *Stats) AddLine()
AddLine will atomically and safely increment LineCnt by one.
func (Stats) Clone ¶
Clone will create a copy of stat that won't trigger race conditions. Use Clone if you are updating and reading from stats at the same time. Read from the clone.
func (Stats) InfoString ¶
InfoString creates a uri-style info string from Stats.
func (Stats) JSONString ¶
func (*Stats) ParseCreated ¶
ParseCreated will attempt to parse the Created field to a time.Time object. ParseCreated expects the Created time string is in time.RFC3339. If there is a parse error then the time.Time zero value is returned.
The returned time will always be in UTC.
func (*Stats) SetChecksum ¶
SetChecksum will correctly calculate and set the base64 encoded checksum.
func (*Stats) SetCreated ¶
SetCreated will set the Created field in the format time.RFC3339 in UTC.