fileUtils

package
v1.7.1 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2020 License: MIT Imports: 5 Imported by: 0

README

Kushuh go file utils

Upsert

Opens a file, and create it if it doesn't exist already. If path is incomplete (intermediate folders are missing), they will also be created automatically.

file, err := fileUtils.Upsert(pathToFile)

Delete

Delete a file.

err := fileUtils.Delete(pathToFile)

OpenFromProjectRoot

Open a file relative to project root, when a command is ran from a sub-directory (which happens with tests and some other commands).

It ensures a file opens from project root with go modules, without having to pass it as an ENV variable (like GOPATH does in non module go packages). It assumes the project folder has an unique name in the entire project tree.

file, err := fileUtils.OpenFromProjectRoot(rootFolderName, relativePath)

FindProjectRoot

Returns the absolute path for the root of a project. It assumes the project folder has an unique name in the entire project tree.

path, err := file_utils.FindProjectRoot(rootFolderName)

2020 Kushuh - MIT license

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Delete added in v1.5.2

func Delete(path string) error

func FindProjectRoot

func FindProjectRoot(rootName string) (string, error)

func OpenFromProjectRoot

func OpenFromProjectRoot(root, path string) (*os.File, error)

func Upsert added in v1.5.2

func Upsert(path string) (*os.File, error)

Open a file and create it if it doesn't exist already

Types

This section is empty.

Jump to

Keyboard shortcuts

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