file

package
v2.1.4 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2025 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// RegularFileModeInt defines the default file mode for regular files as an integer.
	RegularFileModeInt = 0o644
	// RegularFileMode defines the default file mode for regular files.
	RegularFileMode = "0644"

	// SecretFileMode defines the default file mode for files with secrets.
	SecretFileMode = "0640"
)

Variables

This section is empty.

Functions

func Write

func Write(fileMgr OSFileManager, file File) error

Types

type File

type File struct {
	Path    string
	Content []byte
	Type    Type
}

File is a file that is part of NGINX configuration to be written to the file system.

func Convert

func Convert(agentFile agent.File) File

Convert an agent File to an internal File type.

type OSFileManager

type OSFileManager interface {
	// Create file at the provided filepath.
	Create(name string) (*os.File, error)
	// Chmod sets the mode of the file.
	Chmod(file *os.File, mode os.FileMode) error
	// Write writes contents to the file.
	Write(file *os.File, contents []byte) error
	// Open opens the file.
	Open(name string) (*os.File, error)
	// Copy copies from src to dst.
	Copy(dst io.Writer, src io.Reader) error
}

OSFileManager is an interface that exposes File I/O operations.

type StdLibOSFileManager

type StdLibOSFileManager struct{}

StdLibOSFileManager wraps the standard library's file operations. Clients can define an interface with all or a subset StdLibOSFileManager methods and use it in their types or functions, so that they can be unit tested. It is expected that clients generate fakes.

func NewStdLibOSFileManager

func NewStdLibOSFileManager() *StdLibOSFileManager

func (*StdLibOSFileManager) Chmod

func (s *StdLibOSFileManager) Chmod(file *os.File, mode os.FileMode) error

Chmod wraps os.File.Chmod.

func (*StdLibOSFileManager) Copy

func (s *StdLibOSFileManager) Copy(dst io.Writer, src io.Reader) error

Copy wraps io.Copy.

func (*StdLibOSFileManager) Create

func (s *StdLibOSFileManager) Create(name string) (*os.File, error)

Create wraps os.Create.

func (*StdLibOSFileManager) Open

func (s *StdLibOSFileManager) Open(name string) (*os.File, error)

Open wraps os.Open.

func (*StdLibOSFileManager) ReadDir

func (s *StdLibOSFileManager) ReadDir(dirname string) ([]fs.DirEntry, error)

ReadDir wraps os.ReadDir.

func (*StdLibOSFileManager) Remove

func (s *StdLibOSFileManager) Remove(name string) error

Remove wraps os.Remove.

func (*StdLibOSFileManager) Write

func (s *StdLibOSFileManager) Write(file *os.File, contents []byte) error

Write wraps os.File.Write.

type Type

type Type int

Type is the type of File.

const (
	// TypeRegular is the type for regular configuration files.
	TypeRegular Type = iota
	// TypeSecret is the type for secret files.
	TypeSecret
)

func (Type) String

func (t Type) String() string

Directories

Path Synopsis
Code generated by counterfeiter.
Code generated by counterfeiter.

Jump to

Keyboard shortcuts

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