files

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2021 License: MIT Imports: 8 Imported by: 6

Documentation

Index

Constants

View Source
const (
	// INIBool type
	INIBool = iota
	// INIInt type
	INIInt
	// INIFloat type
	INIFloat
	// INIString type
	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

NewINI returns an empty INI structure.

func (*INI) AddSection added in v0.4.0

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

AddSection to INI structure.

func (*INI) Save added in v0.4.0

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

Save outputs 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 contains a variable and its data.

func (*INIField) GetBool added in v0.3.0

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

GetBool returns a field as a bool.

func (*INIField) GetFloat added in v0.3.0

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

GetFloat returns a field as a float64.

func (*INIField) GetInt added in v0.3.0

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

GetInt returns a field as an int.

func (*INIField) SetBool added in v0.3.0

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

SetBool sets a field to a bool.

func (*INIField) SetFloat added in v0.3.0

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

SetFloat sets a field to a float64.

func (*INIField) SetInt added in v0.3.0

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

SetInt sets a field as an int.

func (*INIField) SetString added in v0.3.0

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

SetString sets a 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)

AddFloat adds a new float64 field to the section.

func (*INISection) AddInt added in v0.3.0

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

AddInt adds a new int field to the section.

func (*INISection) AddString added in v0.3.0

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

AddString adds a new string field to the section.

func (*INISection) GetBool added in v0.11.0

func (s *INISection) GetBool(key string, alt bool) bool

GetBool returns a field as a bool, or the alternative.

func (*INISection) GetFloat added in v0.11.0

func (s *INISection) GetFloat(key string, alt float64) float64

GetFloat returns a field as a float64, or the alternative.

func (*INISection) GetInt added in v0.11.0

func (s *INISection) GetInt(key string, alt int) int

GetInt returns a field as an int, or the alternative.

func (*INISection) GetString added in v0.11.0

func (s *INISection) GetString(key, alt string) string

GetString returns a field as a string, or the alternative.

Jump to

Keyboard shortcuts

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