gofile

package module
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: May 21, 2021 License: MIT Imports: 7 Imported by: 2

README

gorepotemplate

Tricky and fun utilities for Go programs.


GitHub Workflow Status Codecov

Contributor Covenant

Twitter Follow GitHub followers


Getting Started

Prerequisites

Developed with $( go version; ). Go is extremely backwards compatible and semver stable. Nearly any v1.x should work fine.


Installation

To use this repo as a template for your own project:

gh repo create -y --public --template "https://github.com/skeptycal/gorepotemplate"

Clone this repo to test and contribute:

# add repo to $GOPATH (xxxxxx is your computer login username)
go get github.com/xxxxxx/gorepotemplate

cd ${GOPATH}/src/github.com/xxxxxx/gorepotemplate

# test results and coverage info
./go.test.sh

# install as a utility package
go install

Use the Issues and PR templates on the GitHub repo page to contribute.


Basic Usage

This is a copy of the example script available in the cmd/example/gorepotemplate folder:

package main

import "github.com/skeptycal/gorepotemplate"

func main() {
    gorepotemplate.Example()
}

To try it out:

# change to the sample folder
cd cmd/example/gorepotemplate

# run the main.go program
go run ./main.go

# to compile as an executable
go build

Code of Conduct and Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us. Please read the Code of Conduct for details before submitting anything.


Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.


Contributors and Inspiration

  • Michael Treanor (GitHub / Twitter) - Initial work, updates, maintainer
  • Francesc Campoy - Inspiration and great YouTube videos!

See also the list of contributors who participated in this project.


License

Licensed under the MIT https://opensource.org/licenses/MIT - see the LICENSE file for details.

Documentation

Overview

Package gofile provides support for file operations.

Index

Constants

View Source
const (
	PathSep = os.PathSeparator
	ListSep = os.PathListSeparator
	NewLine = '\n'
)

Variables

View Source
var (
	// Log is the default global ErrorLogger. It implements the ErrorLogger interface as well as the logrus.Logger interface, which is compatible with the standard library "log" package.
	Log = errorlogger.Log

	// Err is the logging function for the global ErrorLogger.
	Err = errorlogger.Err
)

errorlogger implements error logging to a logrus log by default. It is completely compatible with the standard library 'log' logger API. It provides an efficient and convenient way to log errors with minimal overhead and to temporarily disable or enable logging.

A global Log and Err with default behaviors are supplied that may be aliased if you wish:

Log = errorlogger.Log // implements the ErrorLogger interface
Err = errorlogger.Err // trigger function

ErrorLogger is:

 type ErrorLogger interface {
	 Disable()
	 Enable()
	 Err(err error) error
	 SetLoggerFunc(fn func(args ...interface{}))

	// SetErrorType allows ErrorLogger to wrap errors in a
	// specified custom type. For example, if you want all errors
 // returned to be of type *os.PathError
	 SetErrorType(errType error)
}
View Source
var SameFile = os.SameFile

SameFile reports whether fi1 and fi2 describe the same file. For example, on Unix this means that the device and inode fields of the two underlying structures are identical; on other systems the decision may be based on the path names. SameFile only applies to results returned by this package's Stat. It returns false in other cases.

Functions

func Create

func Create(name string) (io.ReadWriteCloser, error)

Create creates or truncates the named file and returns an opened file as io.ReadWriteCloser.

If the file already exists, it is truncated. If the file does not exist, it is created with mode 0644 (before umask). If successful, methods on the returned File can be used for I/O; the associated file descriptor has mode O_RDWR.

If there is an error, it will be of type *PathError.

func CreateSafe

func CreateSafe(name string) (io.ReadWriteCloser, error)

CreateSafe creates the named file and returns an opened file as io.ReadWriteCloser.

If the file already exists, an error is returned. If the file does not exist, it is created with mode 0644 (before umask). If successful, methods on the returned File can be used for I/O; the associated file descriptor has mode O_RDWR.

If there is an error, it will be of type *PathError.

func InitialCapacity

func InitialCapacity(capacity int64) int

InitialCapacity returns the multiple of 'chunk' one more than needed to accomodate the given capacity.

func IsDir

func IsDir(name string) bool

func IsRegular

func IsRegular(name string) bool

func Mode

func Mode(file string) os.FileMode

Mode returns the filemode of file.

func PWD

func PWD() string

PWD returns a rooted path name corresponding to the current directory. If the current directory can be reached via multiple paths (due to symbolic links), PWD may return any one of them.

If an error occurs, the empty string is returned and the error is logged.

func Stat

func Stat(file string) (os.FileInfo, error)

Stat returns the os.FileInfo for file if it exists. If the file does not exist, nil is returned. Errors are logged if Err is active.

func StatCheck

func StatCheck(filename string) (os.FileInfo, error)

StatCheck returns file information (after symlink evaluation) using os.Stat(). If the file does not exist, is not a regular file, or if the user lacks adequate permissions, an error is returned.

Types

type FileInfo

type FileInfo = fs.FileInfo

A FileInfo describes a file and is returned by Stat and Lstat.

type FileMode

type FileMode = os.FileMode

A FileMode represents a file's mode and permission bits. The bits have the same definition on all systems, so that information about files can be moved from one system to another portably. Not all bits apply to all systems. The only required bit is ModeDir for directories.

type PathError

type PathError = os.PathError

type SortType

type SortType int

SortType is a list of constants representing sort methods for directory listings.

const (
	Alpha SortType = iota + 1
	Size
	Version
	Extension
	Atime
	Ctime
)

func (SortType) String

func (s SortType) String() string

type TimeZone

type TimeZone int
const (
	EST TimeZone = -(5 + iota)
	CST
	MST
	PST
)

American Time Zones

func (TimeZone) String

func (tz TimeZone) String() string

Directories

Path Synopsis
cmd
dir command
redlog command
Package redlogger implements logging to an io.Writer (default stderr) with text wrapped in ANSI escape codes
Package redlogger implements logging to an io.Writer (default stderr) with text wrapped in ANSI escape codes

Jump to

Keyboard shortcuts

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