filer

package
v0.0.0-...-cb73b9c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 23, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package filer is an interface used in the rotatorr subpackages. You may override this to gain more control of operations in your app.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type File

type File struct{}

File can be embedded in a custom type to provide the missing methods for the Filer interface.

Example
package main

import (
	"fmt"

	"golift.io/rotatorr/filer"
)

// Our interface must satify a filer.Filer.
var _ filer.Filer = (*MyFiler)(nil)

// Create a custom Filer that overrides only the Rename method.
type MyFiler struct {
	filer.File
}

func (f *MyFiler) Rename(oldpath, newpath string) error {
	fmt.Printf("Renamed %s -> %s\n", oldpath, newpath)

	return nil
}

func main() {
	// Pass s into any package that uses a filer.Filer.
	s := &MyFiler{}
	_ = s.Rename("old.file", "new.file")
}
Output:

Renamed old.file -> new.file

func (*File) MkdirAll

func (f *File) MkdirAll(path string, perm os.FileMode) error

MkdirAll provides os.MkdirAll.

func (*File) OpenFile

func (f *File) OpenFile(name string, flag int, perm os.FileMode) (*os.File, error)

OpenFile provides os.OpenFile.

func (*File) ReadDir

func (f *File) ReadDir(dirname string) ([]os.FileInfo, error)

ReadDir provides ioutil.ReadDir.

func (*File) Remove

func (f *File) Remove(fileName string) error

Remove provides os.Remove.

func (*File) Rename

func (f *File) Rename(fileName, newPath string) error

Rename provides os.Rename.

func (*File) Stat

func (f *File) Stat(filename string) (*FileInfo, error)

Stat provides custom file stats that wrap os.Stat output.

type FileInfo

type FileInfo struct {
	os.FileInfo
	CreateTime time.Time
}

FileInfo contains normal os.FileInfo + file creation time. Created by Stat(). Sorry in advance.

func Stat

func Stat(filename string) (*FileInfo, error)

Stat returns a *FileInfo struct w/ attached os.FileInfo interface.

type Filer

type Filer interface {
	Remove(fileName string) error
	Rename(fileName, newPath string) error
	ReadDir(dirPath string) ([]os.FileInfo, error)
	MkdirAll(path string, perm os.FileMode) error
	OpenFile(name string, flag int, perm os.FileMode) (*os.File, error)
	Stat(filename string) (*FileInfo, error)
}

Filer is used to override file-managing procedures.

func Default

func Default() Filer

Default returns a Filer interface that works, using default procedures.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL