files

package
v0.10.2 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2020 License: MIT Imports: 8 Imported by: 6

Documentation

Index

Constants

View Source
const (
	INIBool = iota
	INIInt
	INIFloat
	INIString
)

Variables

This section is empty.

Functions

func DirExists

func DirExists(path string) bool

DirExists checks for the existence of a directory. It will return false if a file with that name exists.

func EnsureDirExists

func EnsureDirExists(path string) error

EnsureDirExists by creating it.

func Exists

func Exists(path string) bool

Exists checks for the existence of a file or directory.

func FileExists

func FileExists(path string) bool

FileExists checks for the existence of a file. It will return false if a directory with that name exists.

func LoadJSON

func LoadJSON(fn string, out interface{}) error

LoadJSON and unmarshal structure.

func SaveJSON

func SaveJSON(path string, data interface{}) error

SaveJSON after marshalling neatly.

func WriteFile

func WriteFile(path string, data []byte) error

WriteFile saves a file with private permissions.

Types

type Closer

type Closer struct {
	// contains filtered or unexported fields
}

Closer holds open files to close them all in sequence, logging any errors.

func NewCloser

func NewCloser(files ...*os.File) *Closer

NewCloser returns a pointer to a closer.

func (*Closer) AddFile

func (c *Closer) AddFile(f *os.File) *Closer

AddFile adds a file pointer to the closer's list.

func (*Closer) Close

func (c *Closer) Close(t bool)

Close and remove all files in the list, and log any errors from the Close() call with or without a timestamp.

func (*Closer) SetLogger

func (c *Closer) SetLogger(l *log.Logger)

SetLogger to an alternative logger.

type INI added in v0.3.0

type INI struct {
	// Sections with settings.
	Sections map[string]*INISection
	// Order sections were loaded or added in.
	Order []string
}

INI file base structure.

func LoadINI added in v0.3.0

func LoadINI(filename string) (*INI, error)

LoadINI from file and take a guess at the types of each value.

func NewINI added in v0.4.0

func NewINI() *INI

func (*INI) AddSection added in v0.4.0

func (ini *INI) AddSection(name string) *INISection

func (*INI) Save added in v0.4.0

func (ini *INI) Save(filename string, tabbed bool) error

Saveoutputs the INI to a file. If tabbed is true, the fields will be saved with a tab character prepended.

type INIField added in v0.3.0

type INIField struct {
	// Value will be stripped of surrounding whitespace when loaded.
	Value string
	// Type lets the user choose which Get* method to use when loading unknown files.
	Type byte
	// contains filtered or unexported fields
}

INIField is a variable and its data.

func (*INIField) GetBool added in v0.3.0

func (f *INIField) GetBool(key string) bool

GetBool returns the field as a bool.

func (*INIField) GetFloat added in v0.3.0

func (f *INIField) GetFloat(key string) float64

GetFloat returns the field as a float64.

func (*INIField) GetInt added in v0.3.0

func (f *INIField) GetInt(key string) int

GetInt returns the field as an int.

func (*INIField) SetBool added in v0.3.0

func (f *INIField) SetBool(key string, value bool)

SetBool sets the field as a bool.

func (*INIField) SetFloat added in v0.3.0

func (f *INIField) SetFloat(key string, value float64)

SetFloat sets the field as a float64.

func (*INIField) SetInt added in v0.3.0

func (f *INIField) SetInt(key string, value int)

SetInt sets the field as an int.

func (*INIField) SetString added in v0.3.0

func (f *INIField) SetString(key, value string)

SetString sets the field as a string.

type INISection added in v0.3.0

type INISection struct {
	Fields map[string]*INIField
	// Order fields were loaded or added in.
	Order []string
}

INISection holds one or more fields.

func (*INISection) AddBool added in v0.3.0

func (s *INISection) AddBool(key string, value bool)

AddBool adds a new bool field to the section.

func (*INISection) AddFloat added in v0.3.0

func (s *INISection) AddFloat(key string, value float64)

AddBool adds a new float64 field to the section.

func (*INISection) AddInt added in v0.3.0

func (s *INISection) AddInt(key string, value int)

AddBool adds a new int field to the section.

func (*INISection) AddString added in v0.3.0

func (s *INISection) AddString(key string, value string)

AddBool adds a new string field to the section.

Jump to

Keyboard shortcuts

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