Documentation ¶
Index ¶
- func CopyFileAtomic(dest string, src string, opts *AtomicFileOptions) error
- func CreateAtomic(dest string, r io.Reader, opts *AtomicFileOptions) error
- func DerivedInstanceUUID(input string) uuid.UUID
- func DerivedUUID(input string) uuid.UUID
- func DuplicateBytes(a []byte) []byte
- func DuplicateStrings(a []string) []string
- func EnsureDirectory(path string, perm os.FileMode) error
- func IndexOfString(a []string, s string) int
- func RandomUUID(ns string) uuid.UUID
- func RemoveFromStringSlice(a []string, s string) []string
- func ReplaceFileAtomic(dest string, src string, opts *AtomicFileOptions) error
- func StringInSlice(a []string, s string) bool
- func StringSliceEqual(a []string, b []string) bool
- type AtomicFileOptions
- type BroadcastFlag
- type DirStructure
- func (ds *DirStructure) ChildDir(dirName string, perm os.FileMode) (child *DirStructure)
- func (ds *DirStructure) Ensure() error
- func (ds *DirStructure) EnsureAbsPath(dirPath string) error
- func (ds *DirStructure) EnsureRelDir(dirNames ...string) error
- func (ds *DirStructure) EnsureRelPath(dirPath string) error
- type Flag
- type OnceAgain
- type StablePool
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CopyFileAtomic ¶ added in v0.5.3
func CopyFileAtomic(dest string, src string, opts *AtomicFileOptions) error
CopyFileAtomic is like CreateAtomic but copies content from src to dest. If opts.Mode is 0 CopyFileAtomic tries to set the file mode of src to dest.
func CreateAtomic ¶ added in v0.5.3
func CreateAtomic(dest string, r io.Reader, opts *AtomicFileOptions) error
CreateAtomic creates or overwrites a file at dest atomically using data from r. Atomic means that even in case of a power outage, dest will never be a zero-length file. It will always either contain the previous data (or not exist) or the new data but never anything in between.
func DerivedInstanceUUID ¶ added in v0.5.5
DerivedInstanceUUID returns a new UUID that is derived from the input, but is unique per instance (execution) and therefore is only reproducible with the same process.
func DerivedUUID ¶ added in v0.5.5
DerivedUUID returns a new UUID that is derived from the input only, and therefore is always reproducible.
func DuplicateBytes ¶
DuplicateBytes returns a new copy of the given byte slice.
func DuplicateStrings ¶
DuplicateStrings returns a new copy of the given string slice.
func EnsureDirectory ¶ added in v0.3.0
EnsureDirectory ensures that the given directory exists and that is has the given permissions set. If path is a file, it is deleted and a directory created. If a directory is created, also all missing directories up to the required one are created with the given permissions.
func IndexOfString ¶
IndexOfString returns the index of given string and -1 if its not part of the slice.
func RandomUUID ¶ added in v0.5.5
RandomUUID returns a new random UUID with optionally provided ns
func RemoveFromStringSlice ¶
RemoveFromStringSlice removes the given string from the slice and returns a new slice.
func ReplaceFileAtomic ¶ added in v0.5.3
func ReplaceFileAtomic(dest string, src string, opts *AtomicFileOptions) error
ReplaceFileAtomic replaces the file at dest with the content from src. If dest exists it's file mode copied and used for the replacement. If not, dest will get the same file mode as src. See CopyFileAtomic and CreateAtomic for more information.
func StringInSlice ¶
StringInSlice returns whether the given string is in the string slice.
func StringSliceEqual ¶
StringSliceEqual returns whether the given string slices are equal.
Types ¶
type AtomicFileOptions ¶ added in v0.5.3
type AtomicFileOptions struct { // Mode is the file mode for the new file. If // 0, the file mode will be set to 0600. Mode os.FileMode // TempDir is the path to the temp-directory // that should be used. If empty, it defaults // to the system temp. TempDir string }
AtomicFileOptions holds additional options for manipulating the behavior of CreateAtomic and friends.
type BroadcastFlag ¶ added in v0.9.6
type BroadcastFlag struct {
// contains filtered or unexported fields
}
BroadcastFlag is a simple system to broadcast a flag value.
func NewBroadcastFlag ¶ added in v0.9.6
func NewBroadcastFlag() *BroadcastFlag
NewBroadcastFlag returns a new BroadcastFlag. In the initial state, the flag is not set and the singal does not trigger.
func (*BroadcastFlag) NewFlag ¶ added in v0.9.6
func (bf *BroadcastFlag) NewFlag() *Flag
NewFlag returns a new Flag that listens to this broadcasting flag. In the initial state, the flag is set and the singal triggers. You can call Refresh immediately to get the current state from the broadcasting flag.
func (*BroadcastFlag) NotifyAndReset ¶ added in v0.9.6
func (bf *BroadcastFlag) NotifyAndReset()
NotifyAndReset notifies all flags of this broadcasting flag and resets the internal broadcast flag state.
type DirStructure ¶ added in v0.3.0
type DirStructure struct { sync.Mutex Path string Dir string Perm os.FileMode Parent *DirStructure Children map[string]*DirStructure }
DirStructure represents a directory structure with permissions that should be enforced.
Example ¶
Output: / [755] /repo [777] /repo/b [755] /repo/b/c [750] /repo/b/d [755] /repo/b/d/e [755] /repo/b/d/f [755] /secret [700]
func NewDirStructure ¶ added in v0.3.0
func NewDirStructure(path string, perm os.FileMode) *DirStructure
NewDirStructure returns a new DirStructure.
func (*DirStructure) ChildDir ¶ added in v0.3.0
func (ds *DirStructure) ChildDir(dirName string, perm os.FileMode) (child *DirStructure)
ChildDir adds a new child DirStructure and returns it. Should the child already exist, the existing child is returned and the permissions are updated.
func (*DirStructure) Ensure ¶ added in v0.3.0
func (ds *DirStructure) Ensure() error
Ensure ensures that the specified directory structure (from the first parent on) exists.
func (*DirStructure) EnsureAbsPath ¶ added in v0.3.0
func (ds *DirStructure) EnsureAbsPath(dirPath string) error
EnsureAbsPath ensures that the specified directory structure (from the first parent on) and the given absolute path exists. If the given path is outside the DirStructure, an error will be returned.
func (*DirStructure) EnsureRelDir ¶ added in v0.3.0
func (ds *DirStructure) EnsureRelDir(dirNames ...string) error
EnsureRelDir ensures that the specified directory structure (from the first parent on) and the given relative path (to the DirStructure) exists.
func (*DirStructure) EnsureRelPath ¶ added in v0.3.0
func (ds *DirStructure) EnsureRelPath(dirPath string) error
EnsureRelPath ensures that the specified directory structure (from the first parent on) and the given relative path (to the DirStructure) exists.
type Flag ¶ added in v0.9.6
type Flag struct {
// contains filtered or unexported fields
}
Flag receives changes from its broadcasting flag. A Flag must only be used in one goroutine and is not concurrency safe, but fast.
func (*Flag) IsSet ¶ added in v0.9.6
IsSet returns whether the flag was set since the last Refresh. This does not reset the Flag itself, you'll need to call Refresh for that.
type OnceAgain ¶ added in v0.5.5
type OnceAgain struct {
// contains filtered or unexported fields
}
OnceAgain is an object that will perform only one action "in flight". It's basically the same as sync.Once, but is automatically reused when the function was executed and everyone who waited has left.
func (*OnceAgain) Do ¶ added in v0.5.5
func (o *OnceAgain) Do(f func())
Do calls the function f if and only if Do is being called for the first time for this instance of Once. In other words, given
var once Once
if once.Do(f) is called multiple times, only the first call will invoke f, even if f has a different value in each invocation. A new instance of Once is required for each function to execute.
Do is intended for initialization that must be run exactly once. Since f is niladic, it may be necessary to use a function literal to capture the arguments to a function to be invoked by Do:
config.once.Do(func() { config.init(filename) })
Because no call to Do returns until the one call to f returns, if f causes Do to be called, it will deadlock.
If f panics, Do considers it to have returned; future calls of Do return without calling f.
type StablePool ¶ added in v0.7.1
type StablePool struct { // New optionally specifies a function to generate // a value when Get would otherwise return nil. // It may not be changed concurrently with calls to Get. New func() interface{} // contains filtered or unexported fields }
A StablePool is a drop-in replacement for sync.Pool that is slower, but predictable. A StablePool is a set of temporary objects that may be individually saved and retrieved.
In contrast to sync.Pool, items are not removed automatically. Every item will be returned at some point. Items are returned in a FIFO manner in order to evenly distribute usage of a set of items.
A StablePool is safe for use by multiple goroutines simultaneously and must not be copied after first use.
func (*StablePool) Get ¶ added in v0.7.1
func (p *StablePool) Get() interface{}
Get returns the next item from the Pool, removes it from the Pool, and returns it to the caller. In contrast to sync.Pool, Get never ignores the pool. Callers should not assume any relation between values passed to Put and the values returned by Get.
If Get would otherwise return nil and p.New is non-nil, Get returns the result of calling p.New.
func (*StablePool) Max ¶ added in v0.7.1
func (p *StablePool) Max() int
Max returns the amount of items the pool held at maximum.
func (*StablePool) Put ¶ added in v0.7.1
func (p *StablePool) Put(x interface{})
Put adds x to the pool.
func (*StablePool) Size ¶ added in v0.7.3
func (p *StablePool) Size() int
Size returns the amount of items the pool currently holds.