Documentation
¶
Overview ¶
Package write provides a generic interface for writing files.
Index ¶
- type AppendSectionWriter
- type BaseWriter
- type ChainedWriter
- type Change
- type CompositeWriter
- func (cw *CompositeWriter) AddWriter(condition WriterCondition, writer Writer, priority int)
- func (cw *CompositeWriter) CanWrite(path string) bool
- func (cw *CompositeWriter) GetMatchingWriters(path string) []Writer
- func (cw *CompositeWriter) NeedsWrite(path string, content []byte) (bool, error)
- func (cw *CompositeWriter) Write(path string, content []byte, options WriteOptions) error
- type ConcurrentWriteManager
- func (cwm *ConcurrentWriteManager) AddWriter(name string, writer Writer, owner string)
- func (cwm *ConcurrentWriteManager) GetLockManager() *FileLockManager
- func (cwm *ConcurrentWriteManager) GetStats() ConcurrentWriteStats
- func (cwm *ConcurrentWriteManager) GetWriter(name string) (*CoordinatedWriter, bool)
- func (cwm *ConcurrentWriteManager) RemoveWriter(name string)
- func (cwm *ConcurrentWriteManager) Stop()
- func (cwm *ConcurrentWriteManager) WriteWithWriter(writerName, path string, content []byte, options WriteOptions) error
- type ConcurrentWriteStats
- type ConditionalWriter
- type CoordinatedWriter
- type DryRunWriter
- type FileLock
- type FileLockInfo
- type FileLockManager
- func (flm *FileLockManager) AcquireLock(path, owner string) (*FileLock, error)
- func (flm *FileLockManager) AcquireLockWithContext(ctx context.Context, path, owner string) (*FileLock, error)
- func (flm *FileLockManager) GetActiveLocks() []FileLockInfo
- func (flm *FileLockManager) GetLockInfo(path string) (*FileLock, error)
- func (flm *FileLockManager) IsLocked(path string) bool
- func (flm *FileLockManager) ReleaseLock(lock *FileLock) error
- func (flm *FileLockManager) Stop()
- type FilterWriter
- type LockOption
- type LoggingWriter
- type ReplaceSegmentWriter
- func (rsw *ReplaceSegmentWriter) CanWrite(path string) bool
- func (rsw *ReplaceSegmentWriter) NeedsWrite(path string, content []byte) (bool, error)
- func (rsw *ReplaceSegmentWriter) SetMarkers(begin, end string)
- func (rsw *ReplaceSegmentWriter) Write(path string, content []byte, options WriteOptions) error
- type RetryWriter
- type SkipIfExistsWriter
- type TemplateWriter
- type TimestampWriter
- type ValidatingWriter
- type WriteOptions
- type Writer
- type WriterCondition
- func AndCondition(conditions ...WriterCondition) WriterCondition
- func ExtensionCondition(extensions ...string) WriterCondition
- func NotCondition(condition WriterCondition) WriterCondition
- func OrCondition(conditions ...WriterCondition) WriterCondition
- func PatternCondition(patterns ...string) WriterCondition
- func PrefixCondition(prefixes ...string) WriterCondition
- type WriterRule
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AppendSectionWriter ¶
type AppendSectionWriter struct {
// contains filtered or unexported fields
}
func NewAppendSectionWriter ¶
func NewAppendSectionWriter(baseWriter Writer, anchor string) *AppendSectionWriter
func (*AppendSectionWriter) CanWrite ¶
func (asw *AppendSectionWriter) CanWrite(path string) bool
func (*AppendSectionWriter) NeedsWrite ¶
func (asw *AppendSectionWriter) NeedsWrite(path string, content []byte) (bool, error)
func (*AppendSectionWriter) Write ¶
func (asw *AppendSectionWriter) Write(path string, content []byte, options WriteOptions) error
type BaseWriter ¶
type BaseWriter struct{}
func NewBaseWriter ¶
func NewBaseWriter() *BaseWriter
func (*BaseWriter) CanWrite ¶
func (bw *BaseWriter) CanWrite(path string) bool
func (*BaseWriter) NeedsWrite ¶
func (bw *BaseWriter) NeedsWrite(path string, content []byte) (bool, error)
func (*BaseWriter) Write ¶
func (bw *BaseWriter) Write(path string, content []byte, options WriteOptions) error
type ChainedWriter ¶
type ChainedWriter struct {
// contains filtered or unexported fields
}
func NewChainedWriter ¶
func NewChainedWriter(writers ...Writer) *ChainedWriter
func (*ChainedWriter) CanWrite ¶
func (cw *ChainedWriter) CanWrite(path string) bool
func (*ChainedWriter) NeedsWrite ¶
func (cw *ChainedWriter) NeedsWrite(path string, content []byte) (bool, error)
func (*ChainedWriter) Write ¶
func (cw *ChainedWriter) Write(path string, content []byte, options WriteOptions) error
type CompositeWriter ¶
type CompositeWriter struct {
// contains filtered or unexported fields
}
func NewCompositeWriter ¶
func NewCompositeWriter() *CompositeWriter
func (*CompositeWriter) AddWriter ¶
func (cw *CompositeWriter) AddWriter(condition WriterCondition, writer Writer, priority int)
func (*CompositeWriter) CanWrite ¶
func (cw *CompositeWriter) CanWrite(path string) bool
func (*CompositeWriter) GetMatchingWriters ¶
func (cw *CompositeWriter) GetMatchingWriters(path string) []Writer
func (*CompositeWriter) NeedsWrite ¶
func (cw *CompositeWriter) NeedsWrite(path string, content []byte) (bool, error)
func (*CompositeWriter) Write ¶
func (cw *CompositeWriter) Write(path string, content []byte, options WriteOptions) error
type ConcurrentWriteManager ¶
type ConcurrentWriteManager struct {
// contains filtered or unexported fields
}
func NewConcurrentWriteManager ¶
func NewConcurrentWriteManager() *ConcurrentWriteManager
func (*ConcurrentWriteManager) AddWriter ¶
func (cwm *ConcurrentWriteManager) AddWriter(name string, writer Writer, owner string)
func (*ConcurrentWriteManager) GetLockManager ¶
func (cwm *ConcurrentWriteManager) GetLockManager() *FileLockManager
func (*ConcurrentWriteManager) GetStats ¶
func (cwm *ConcurrentWriteManager) GetStats() ConcurrentWriteStats
func (*ConcurrentWriteManager) GetWriter ¶
func (cwm *ConcurrentWriteManager) GetWriter(name string) (*CoordinatedWriter, bool)
func (*ConcurrentWriteManager) RemoveWriter ¶
func (cwm *ConcurrentWriteManager) RemoveWriter(name string)
func (*ConcurrentWriteManager) Stop ¶
func (cwm *ConcurrentWriteManager) Stop()
func (*ConcurrentWriteManager) WriteWithWriter ¶
func (cwm *ConcurrentWriteManager) WriteWithWriter(writerName, path string, content []byte, options WriteOptions) error
type ConcurrentWriteStats ¶
type ConcurrentWriteStats struct {
ActiveLocks int `json:"active_locks"`
WriterCount int `json:"writer_count"`
LockDetails []FileLockInfo `json:"lock_details"`
}
type ConditionalWriter ¶
type ConditionalWriter struct {
// contains filtered or unexported fields
}
func NewConditionalWriter ¶
func NewConditionalWriter(condition WriterCondition, primary, secondary Writer) *ConditionalWriter
func (*ConditionalWriter) CanWrite ¶
func (cw *ConditionalWriter) CanWrite(path string) bool
func (*ConditionalWriter) NeedsWrite ¶
func (cw *ConditionalWriter) NeedsWrite(path string, content []byte) (bool, error)
func (*ConditionalWriter) Write ¶
func (cw *ConditionalWriter) Write(path string, content []byte, options WriteOptions) error
type CoordinatedWriter ¶
type CoordinatedWriter struct {
// contains filtered or unexported fields
}
func NewCoordinatedWriter ¶
func NewCoordinatedWriter(baseWriter Writer, lockManager *FileLockManager, owner string) *CoordinatedWriter
func (*CoordinatedWriter) CanWrite ¶
func (cw *CoordinatedWriter) CanWrite(path string) bool
func (*CoordinatedWriter) NeedsWrite ¶
func (cw *CoordinatedWriter) NeedsWrite(path string, content []byte) (bool, error)
func (*CoordinatedWriter) Write ¶
func (cw *CoordinatedWriter) Write(path string, content []byte, options WriteOptions) error
type DryRunWriter ¶
type DryRunWriter struct {
// contains filtered or unexported fields
}
func NewDryRunWriter ¶
func NewDryRunWriter() *DryRunWriter
func (*DryRunWriter) CanWrite ¶
func (drw *DryRunWriter) CanWrite(path string) bool
func (*DryRunWriter) GetChanges ¶
func (drw *DryRunWriter) GetChanges() []Change
func (*DryRunWriter) NeedsWrite ¶
func (drw *DryRunWriter) NeedsWrite(path string, content []byte) (bool, error)
func (*DryRunWriter) Reset ¶
func (drw *DryRunWriter) Reset()
func (*DryRunWriter) Write ¶
func (drw *DryRunWriter) Write(path string, content []byte, options WriteOptions) error
type FileLockInfo ¶
type FileLockInfo struct {
Path string `json:"path"`
Acquired time.Time `json:"acquired"`
Owner string `json:"owner"`
Refs int `json:"refs"`
}
FileLockInfo contains the serializable information about a file lock
type FileLockManager ¶
type FileLockManager struct {
// contains filtered or unexported fields
}
func NewFileLockManager ¶
func NewFileLockManager(opts ...LockOption) *FileLockManager
func (*FileLockManager) AcquireLock ¶
func (flm *FileLockManager) AcquireLock(path, owner string) (*FileLock, error)
func (*FileLockManager) AcquireLockWithContext ¶
func (*FileLockManager) GetActiveLocks ¶
func (flm *FileLockManager) GetActiveLocks() []FileLockInfo
func (*FileLockManager) GetLockInfo ¶
func (flm *FileLockManager) GetLockInfo(path string) (*FileLock, error)
func (*FileLockManager) IsLocked ¶
func (flm *FileLockManager) IsLocked(path string) bool
func (*FileLockManager) ReleaseLock ¶
func (flm *FileLockManager) ReleaseLock(lock *FileLock) error
func (*FileLockManager) Stop ¶
func (flm *FileLockManager) Stop()
type FilterWriter ¶
type FilterWriter struct {
// contains filtered or unexported fields
}
func NewFilterWriter ¶
func (*FilterWriter) CanWrite ¶
func (fw *FilterWriter) CanWrite(path string) bool
func (*FilterWriter) NeedsWrite ¶
func (fw *FilterWriter) NeedsWrite(path string, content []byte) (bool, error)
func (*FilterWriter) Write ¶
func (fw *FilterWriter) Write(path string, content []byte, options WriteOptions) error
type LockOption ¶
type LockOption func(*FileLockManager)
func WithCleanupInterval ¶
func WithCleanupInterval(interval time.Duration) LockOption
func WithLockTimeout ¶
func WithLockTimeout(timeout time.Duration) LockOption
type LoggingWriter ¶
type LoggingWriter struct {
// contains filtered or unexported fields
}
func NewLoggingWriter ¶
func NewLoggingWriter(baseWriter Writer, logFunc func(string, ...any)) *LoggingWriter
func (*LoggingWriter) CanWrite ¶
func (lw *LoggingWriter) CanWrite(path string) bool
func (*LoggingWriter) NeedsWrite ¶
func (lw *LoggingWriter) NeedsWrite(path string, content []byte) (bool, error)
func (*LoggingWriter) Write ¶
func (lw *LoggingWriter) Write(path string, content []byte, options WriteOptions) error
type ReplaceSegmentWriter ¶
type ReplaceSegmentWriter struct {
// contains filtered or unexported fields
}
func NewReplaceSegmentWriter ¶
func NewReplaceSegmentWriter(baseWriter Writer) *ReplaceSegmentWriter
func (*ReplaceSegmentWriter) CanWrite ¶
func (rsw *ReplaceSegmentWriter) CanWrite(path string) bool
func (*ReplaceSegmentWriter) NeedsWrite ¶
func (rsw *ReplaceSegmentWriter) NeedsWrite(path string, content []byte) (bool, error)
func (*ReplaceSegmentWriter) SetMarkers ¶
func (rsw *ReplaceSegmentWriter) SetMarkers(begin, end string)
func (*ReplaceSegmentWriter) Write ¶
func (rsw *ReplaceSegmentWriter) Write(path string, content []byte, options WriteOptions) error
type RetryWriter ¶
type RetryWriter struct {
// contains filtered or unexported fields
}
func NewRetryWriter ¶
func NewRetryWriter(writer Writer, maxRetries int) *RetryWriter
func (*RetryWriter) CanWrite ¶
func (rw *RetryWriter) CanWrite(path string) bool
func (*RetryWriter) NeedsWrite ¶
func (rw *RetryWriter) NeedsWrite(path string, content []byte) (bool, error)
func (*RetryWriter) SetBackoff ¶
func (rw *RetryWriter) SetBackoff(backoff func(int) time.Duration)
func (*RetryWriter) Write ¶
func (rw *RetryWriter) Write(path string, content []byte, options WriteOptions) error
type SkipIfExistsWriter ¶
type SkipIfExistsWriter struct {
// contains filtered or unexported fields
}
func NewSkipIfExistsWriter ¶
func NewSkipIfExistsWriter(baseWriter Writer) *SkipIfExistsWriter
func (*SkipIfExistsWriter) CanWrite ¶
func (siw *SkipIfExistsWriter) CanWrite(path string) bool
func (*SkipIfExistsWriter) NeedsWrite ¶
func (siw *SkipIfExistsWriter) NeedsWrite(path string, content []byte) (bool, error)
func (*SkipIfExistsWriter) Write ¶
func (siw *SkipIfExistsWriter) Write(path string, content []byte, options WriteOptions) error
type TemplateWriter ¶
type TemplateWriter struct {
// contains filtered or unexported fields
}
func NewTemplateWriter ¶
func NewTemplateWriter(baseWriter Writer, header, footer string) *TemplateWriter
func (*TemplateWriter) CanWrite ¶
func (tw *TemplateWriter) CanWrite(path string) bool
func (*TemplateWriter) NeedsWrite ¶
func (tw *TemplateWriter) NeedsWrite(path string, content []byte) (bool, error)
func (*TemplateWriter) Write ¶
func (tw *TemplateWriter) Write(path string, content []byte, options WriteOptions) error
type TimestampWriter ¶
type TimestampWriter struct {
// contains filtered or unexported fields
}
func NewTimestampWriter ¶
func NewTimestampWriter(baseWriter Writer) *TimestampWriter
func (*TimestampWriter) CanWrite ¶
func (tw *TimestampWriter) CanWrite(path string) bool
func (*TimestampWriter) NeedsWrite ¶
func (tw *TimestampWriter) NeedsWrite(path string, content []byte) (bool, error)
func (*TimestampWriter) SetFormat ¶
func (tw *TimestampWriter) SetFormat(format string)
func (*TimestampWriter) Write ¶
func (tw *TimestampWriter) Write(path string, content []byte, options WriteOptions) error
type ValidatingWriter ¶
type ValidatingWriter struct {
// contains filtered or unexported fields
}
func NewValidatingWriter ¶
func NewValidatingWriter(writer Writer, validator func(path string, content []byte) error) *ValidatingWriter
func (*ValidatingWriter) CanWrite ¶
func (vw *ValidatingWriter) CanWrite(path string) bool
func (*ValidatingWriter) NeedsWrite ¶
func (vw *ValidatingWriter) NeedsWrite(path string, content []byte) (bool, error)
func (*ValidatingWriter) Write ¶
func (vw *ValidatingWriter) Write(path string, content []byte, options WriteOptions) error
type WriteOptions ¶
type WriterCondition ¶
func AndCondition ¶
func AndCondition(conditions ...WriterCondition) WriterCondition
func ExtensionCondition ¶
func ExtensionCondition(extensions ...string) WriterCondition
func NotCondition ¶
func NotCondition(condition WriterCondition) WriterCondition
func OrCondition ¶
func OrCondition(conditions ...WriterCondition) WriterCondition
func PatternCondition ¶
func PatternCondition(patterns ...string) WriterCondition
func PrefixCondition ¶
func PrefixCondition(prefixes ...string) WriterCondition
type WriterRule ¶
type WriterRule struct {
Condition WriterCondition
Writer Writer
Priority int
}
Click to show internal directories.
Click to hide internal directories.