Documentation ¶
Index ¶
Constants ¶
View Source
const ( // DefaultMaxSize is the default maximum size of record file. DefaultMaxSize = 100 // DefaultMaxBackups is the default maximum count of backup. DefaultMaxBackups = 10 // DefaultBufferSize is the default size of buffer container. DefaultBufferSize = 100 )
View Source
const ( // RecordFilePrefix is prefix of record file name. RecordFilePrefix = "record" // RecordFileExt is extension of record file name. RecordFileExt = "csv" )
View Source
const ( // Peer has been downloaded successfully. PeerStateSucceeded = iota // Peer has been downloaded failed. PeerStateFailed // Peer has been back-to-source downloaded successfully. PeerStateBackToSourceSucceeded // Peer has been back-to-source downloaded failed. PeerStateBackToSourceFailed )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Option ¶
type Option func(s *storage)
Option is a functional option for configuring the Storage.
func WithBufferSize ¶
WithCacheSize sets the size of buffer container, if the buffer is full, write all the records in the buffer to the file.
func WithMaxBackups ¶
WithMaxBackups sets the maximum number of storage files to retain.
func WithMaxSize ¶
WithMaxSize sets the maximum size in megabytes of storage file.
type Record ¶
type Record struct { // ID is peer id. ID string `csv:"id"` // IP is host ip. IP string `csv:"ip"` // Hostname is host name. Hostname string `csv:"hostname"` // Tag is peer tag. Tag string `csv:"tag"` // Cost is the task download time(millisecond). Cost uint32 `csv:"cost"` // PieceCount is total piece count. PieceCount int32 `csv:"pieceCount"` // TotalPieceCount is total piece count. TotalPieceCount int32 `csv:"totalPieceCount"` // ContentLength is task total content length. ContentLength int64 `csv:"contentLength"` // SecurityDomain is security domain of host. SecurityDomain string `csv:"securityDomain"` // IDC is internet data center of host. IDC string `csv:"idc"` // NetTopology is network topology of host. // Example: switch|router|... NetTopology string `csv:"netTopology"` // Location is location of host. // Example: country|province|... Location string `csv:"location"` // FreeUploadLoad is free upload load of host. FreeUploadLoad int32 `csv:"freeUpoladLoad"` // State is the download state of the peer. State int `csv:"state"` // HostType is peer host type. HostType int `csv:"hostType"` // CreateAt is peer create nanosecond time. CreateAt int64 `csv:"createAt"` // UpdateAt is peer update nanosecond time. UpdateAt int64 `csv:"updateAt"` // ParentID is parent peer id. ParentID string `csv:"parentID"` // ParentIP is parent host ip. ParentIP string `csv:"parentIP"` // ParentHostname is parent hostname. ParentHostname string `csv:"parentHostname"` // ParentTag is parent peer tag. ParentTag string `csv:"parentTag"` // ParentPieceCount is parent total piece count. ParentPieceCount int32 `csv:"parentPieceCount"` // ParentSecurityDomain is parent security domain of host. ParentSecurityDomain string `csv:"parentSecurityDomain"` // ParentIDC is parent internet data center of host. ParentIDC string `csv:"parentIDC"` // ParentNetTopology is parent network topology of host. // Example: switch|router|... ParentNetTopology string `csv:"parentNetTopology"` // ParentLocation is parent location of host. // Example: country|province|... ParentLocation string `csv:"parentLocation"` // ParentFreeUploadLoad is parent free upload load of host. ParentFreeUploadLoad int32 `csv:"parentFreeUploadLoad"` // ParentHostType is parent host type. ParentHostType int `csv:"parentHostType"` // ParentCreateAt is parent peer create nanosecond time. ParentCreateAt int64 `csv:"parentCreateAt"` // ParentUpdateAt is parent peer update nanosecond time. ParentUpdateAt int64 `csv:"parentUpdateAt"` }
Record contains content for record.
type Storage ¶
type Storage interface { // Create inserts the record into csv file. Create(Record) error // List returns all of records in csv file. List() ([]Record, error) // Count returns the count of records. Count() int64 // Open opens storage for read, it returns io.ReadCloser of storage files. Open() (io.ReadCloser, error) // Clear removes all record files. Clear() error }
Storage is the interface used for storage.
Click to show internal directories.
Click to hide internal directories.