file

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package file contains helper functions to interact with files.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckDirExists

func CheckDirExists(dir string) error

CheckDirExists checks that whether the provided directory exists.

func WriteFile

func WriteFile(filename string, data []byte, perm os.FileMode, opts ...Option) error

WriteFile writes the supplied data to the file.

Types

type Option

type Option func(o *options)

Option is the type to add optional behavior changes.

func WithBackup

func WithBackup(pattern string) Option

WithBackup specifies the backup pattern for backing up files that already exist. If the filename has an extension, the pattern is inserted between filename base and extension. If the filename does not have an extension, the pattern is added as a suffix.

WithBackup takes precedence over WithForce, meaning, if a file exists, it is backed up and not overwritten.

Example: (pattern: 2021-05-06) - example.txt -> example.2021-05-06.txt - example -> example.2021-05-06

func WithForce

func WithForce(force bool) Option

WithForce specifies whether a file should be overwritten if it already exists.

WithBackup takes precedence over WithForce, meaning, if a file exists, it is backed up and not overwritten.

Jump to

Keyboard shortcuts

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