conf

package module
v1.7.2 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2025 License: MIT Imports: 6 Imported by: 3

README

goconf

This is a preferences API inspired by that of fyne

Create this basically because, the fyne configuration api saves its files in [configuration path]/fyne/appID/config.json and with this case, I want it to be saved in [configuration path]/appID/config.json without any trace of that framework, since it is a GUI framework, and I would like to be able to apply that to a CLI application

Usage/Examples

package main

import (
 "fmt"

 conf "github.com/Tom5521/goconf"
)

func main() {
 settings, err := conf.New("myapp")
 if err != nil {
  panic(err)
 }
 settings.SetString("c1", "value1")

 fmt.Println(settings.String("c1"))
}

Installation

Install my-project with go get

go get -u github.com/Tom5521/goconf@latest

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

View Source
var IsUnix = func() bool {
	unixes := [...]string{
		"netbsd",
		"linux",
		"openbsd",
		"darwin",
	}

	for _, o := range unixes {
		if runtime.GOOS == o {
			return true
		}
	}
	return false
}()

Functions

func SetFor added in v1.6.0

func SetFor[T any](p *Preferences, key string, v T)

Types

type Field added in v1.5.0

type Field struct {
	Key     string
	Default any
}

type Preferences

type Preferences struct {
	// If true, the file will be written every time a Set operation is executed.
	Autosave bool
	// contains filtered or unexported fields
}

func New

func New(id string) (p *Preferences, err error)

func (*Preferences) Bool

func (p *Preferences) Bool(key string) bool

func (*Preferences) BoolList

func (p *Preferences) BoolList(key string) []bool

func (*Preferences) Check added in v1.4.0

func (p *Preferences) Check(key string) bool

func (Preferences) ConfigFile added in v1.4.0

func (p Preferences) ConfigFile() string

func (*Preferences) CreateNewFields added in v1.5.0

func (p *Preferences) CreateNewFields(overwrite bool, fields ...Field)

func (*Preferences) Error added in v1.5.0

func (p *Preferences) Error() error

Returns possible errors made when autosaving.

func (*Preferences) Float

func (p *Preferences) Float(key string) float64

func (*Preferences) FloatList

func (p *Preferences) FloatList(key string) []float64

func (Preferences) ID added in v1.6.0

func (p Preferences) ID() string

func (*Preferences) Int

func (p *Preferences) Int(key string) int

func (*Preferences) IntList

func (p *Preferences) IntList(key string) []int

func (*Preferences) Load added in v1.7.2

func (p *Preferences) Load(key string) any

func (*Preferences) Refresh added in v1.5.0

func (p *Preferences) Refresh() error

func (*Preferences) RemoveValue

func (p *Preferences) RemoveValue(key string)

func (*Preferences) Save added in v1.4.0

func (p *Preferences) Save() error

func (*Preferences) Set

func (p *Preferences) Set(key string, value any)

func (*Preferences) SetBool

func (p *Preferences) SetBool(key string, value bool)

func (*Preferences) SetBoolList

func (p *Preferences) SetBoolList(key string, value []bool)

func (*Preferences) SetFloat

func (p *Preferences) SetFloat(key string, value float64)

func (*Preferences) SetFloatList

func (p *Preferences) SetFloatList(key string, value []float64)

func (*Preferences) SetInt

func (p *Preferences) SetInt(key string, value int)

func (*Preferences) SetIntList

func (p *Preferences) SetIntList(key string, value []int)

func (*Preferences) SetString

func (p *Preferences) SetString(key string, value string)

func (*Preferences) SetStringList

func (p *Preferences) SetStringList(key string, value []string)

func (*Preferences) SetValue added in v1.4.0

func (p *Preferences) SetValue(key string, value reflect.Value)

func (*Preferences) String

func (p *Preferences) String(key string) string

func (*Preferences) StringList

func (p *Preferences) StringList(key string) []string

func (Preferences) Values added in v1.4.0

func (p Preferences) Values() map[string]any

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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