tmp

package
v12.41.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2022 License: Apache-2.0 Imports: 5 Imported by: 2

Documentation

Overview

Package tmp provides methods and structs for working with temporary data

Index

Examples

Constants

This section is empty.

Variables

View Source
var DefaultDirPerms = os.FileMode(0750)

DefaultDirPerms is default permissions for directories

View Source
var DefaultFilePerms = os.FileMode(0640)

DefaultFilePerms is default permissions for files

View Source
var Dir = "/tmp"

Dir is default temporary directory

Functions

This section is empty.

Types

type Temp

type Temp struct {
	Dir       string
	DirPerms  os.FileMode
	FilePerms os.FileMode
	// contains filtered or unexported fields
}

Temp is basic temp struct

func NewTemp

func NewTemp(dir ...string) (*Temp, error)

NewTemp creates new Temp structure

Example
tmp, _ := NewTemp()

fmt.Println(tmp.Dir)
Output:

/tmp

func (*Temp) Clean

func (t *Temp) Clean()

Clean removes all temporary targets

Example
tmp, _ := NewTemp()

tmp.MkDir()

// All temporary data will be removed
tmp.Clean()
Output:

func (*Temp) MkDir

func (t *Temp) MkDir(nameSuffix ...string) (string, error)

MkDir makes temporary directory

Example
tmp, _ := NewTemp()

fmt.Println(tmp.MkDir())
fmt.Println(tmp.MkDir("test123"))

tmp.Clean()
Output:

func (*Temp) MkFile

func (t *Temp) MkFile(nameSuffix ...string) (*os.File, string, error)

MkFile makes temporary file

Example
tmp, _ := NewTemp()

fmt.Println(tmp.MkFile())
fmt.Println(tmp.MkFile("test123"))

tmp.Clean()
Output:

func (*Temp) MkName

func (t *Temp) MkName(nameSuffix ...string) string

MkName returns name for temporary object

Example
tmp, _ := NewTemp()

fmt.Println(tmp.MkDir())
fmt.Println(tmp.MkDir("test123"))
Output:

Jump to

Keyboard shortcuts

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