yocke

package
v0.0.0-...-9853328 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2023 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CF_DICT = iota
	CF_ARR
	CF_STR
	CF_NUM
	CF_BOOL
	CF_DATA
	CF_UID
	CF_REAL
	CF_NONE
)

Variables

This section is empty.

Functions

func FreeEnv

func FreeEnv[T any]()

Types

type CFArray

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

func (CFArray) Copy

func (c CFArray) Copy() CFArray

func (CFArray) Foreach

func (c CFArray) Foreach(cb func(idx int, v CFValue) bool)

func (CFArray) GetByIdx

func (c CFArray) GetByIdx(idx int) CFValue

func (CFArray) SetByIdx

func (c CFArray) SetByIdx(idx int, v any) error

func (CFArray) Type

func (CFArray) Type() uint8

type CFBool

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

func (CFBool) Type

func (CFBool) Type() uint8

type CFData

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

func (CFData) Type

func (CFData) Type() uint8

type CFDictionary

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

func (CFDictionary) Foreach

func (c CFDictionary) Foreach(cb func(k string, v CFValue) bool)

func (CFDictionary) GetCFValue

func (c CFDictionary) GetCFValue(field string) CFValue

func (CFDictionary) Set

func (c CFDictionary) Set(field string, v any)

func (CFDictionary) Type

func (CFDictionary) Type() uint8

type CFNone

type CFNone struct{}

func (CFNone) Type

func (CFNone) Type() uint8

type CFNumber

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

func (CFNumber) Type

func (CFNumber) Type() uint8

type CFReal

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

func (CFReal) Type

func (CFReal) Type() uint8

type CFString

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

func (CFString) Type

func (CFString) Type() uint8

type CFUID

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

func (CFUID) Type

func (CFUID) Type() uint8

type CFValue

type CFValue interface {
	Type() uint8
}

func GetPlistValue

func GetPlistValue(v CFValue, name string) CFValue

type Env

type Env[T any] struct {
	// contains filtered or unexported fields
}

func GetEnv

func GetEnv[T any]() *Env[T]

func InitEnv

func InitEnv[T any](opt *EnvOpt[T], opts ...viper.Option) *Env[T]

func (*Env[T]) Conf

func (e *Env[T]) Conf() T

func (*Env[T]) Save

func (e *Env[T]) Save(files ...string) error

func (*Env[T]) SetValue

func (e *Env[T]) SetValue(k string, v any)

func (*Env[T]) String

func (e *Env[T]) String() string

func (*Env[T]) User

func (e *Env[T]) User() *user.User

func (*Env[T]) Viper

func (e *Env[T]) Viper() *viper.Viper

type EnvOpt

type EnvOpt[T any] struct {
	Conf     T
	Workdir  string
	Subdirs  []string
	ConfTmpl string
	Filename string
}

func (*EnvOpt[T]) String

func (opt *EnvOpt[T]) String() string

type MetaArr

type MetaArr = []any

type MetaMap

type MetaMap = map[string]any

type MetaTable

type MetaTable interface {
	// SetValue set MetaTable's value and have two different rules:
	// regedit(windows): MetaValue ✔ MetaMap ✔ MetaArr x (MetaArr not work);
	// plist(darwin, posix): MetaValue ✔ MetaMap ✔ MetaArr ✔
	SetValue(MetaValue)
	// SafeSetValue set MetaTable's value when key isn't exist and have two different rules:
	// regedit(windows): MetaValue ✔ MetaMap ✔ MetaArr x (MetaArr not work);
	// plist(darwin, posix): MetaValue ✔ MetaMap ✔ MetaArr ✔
	SafeSetValue(MetaValue)
	// GetValue return MetaValue according to key
	GetValue(string) MetaValue
	// CreateSubTable have two different effect:
	// regedit(windows): create sub key and written file depond on its feture.
	// plist(darwin, posix): create sub element of map or array, but not be saved automatically
	// comparing regedit. It's required to call Write method save manually.
	CreateSubTable(string) MetaTable
	// Write to persist MetaValue in disk.
	// note: The regedit (windows) is written when it is created,
	// and this method is only valid for plist (darwin, posix).
	// The regedit is just an empty method.
	Write() error
	// Backup save a copy which could restore MetaValue
	Backup() error
	// Close to free MetaTable memory
	Close()
}

MetaTable is an interface to abstract plist(darwin) and regedit(windows). In other posix os, uniform use of plist as MetaTable interface implement

type MetaValue

type MetaValue = any

type PlistFile

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

PlistFile manage plist, which serves for PosixMetaTable

func CreatePlistFile

func CreatePlistFile(file string) (*PlistFile, error)

CreatePlistFile create specify plist when plist isn't exist

func OpenPlistFile

func OpenPlistFile(file string) (*PlistFile, error)

OpenPlistFile open specify plist

func (*PlistFile) Append

func (pf *PlistFile) Append(value any) error

func (*PlistFile) Backup

func (pf *PlistFile) Backup() error

func (*PlistFile) Free

func (pf *PlistFile) Free()

func (*PlistFile) GetArr

func (pf *PlistFile) GetArr() CFArray

GetDict returns CFArray. If not exist in plist, it'll return a empty CFArray.

func (*PlistFile) GetArrByField

func (pf *PlistFile) GetArrByField(field string) CFArray

GetArrByField return CFArray according to field

func (*PlistFile) GetBaseValue

func (pf *PlistFile) GetBaseValue() CFValue

GetBaseValue returns CFValue. If not exist in plist, it'll return CFNone.

func (*PlistFile) GetDict

func (pf *PlistFile) GetDict() CFDictionary

GetDict returns CFDictionary. If not exist in plist, it'll return a empty CFDictionary.

func (*PlistFile) GetValue

func (pf *PlistFile) GetValue(key string) CFValue

GetValue returns CFValue according to key

func (*PlistFile) Len

func (pf *PlistFile) Len() int

Len return plist length. Length of array or map depend on elements amount. For other type that include string, date, number and so on, it ever returns 1.

func (*PlistFile) SafeSet

func (pf *PlistFile) SafeSet(key string, value any) error

func (*PlistFile) Set

func (pf *PlistFile) Set(value any)

Set set root element of plist

func (*PlistFile) SetByField

func (pf *PlistFile) SetByField(field string, value CFValue) error

SetByField set element in sprcify field, which support recurse and meant that you can set a.b.c field.

func (*PlistFile) SetByIdx

func (pf *PlistFile) SetByIdx(idx int, value any) error

SetByIdx set element in specify position if position is available. For map, index will be convert string as key to set.

func (*PlistFile) Write

func (pf *PlistFile) Write() error

type PosixEnvVar

type PosixEnvVar struct{}

func NewEnvVar

func NewEnvVar() *PosixEnvVar

func (*PosixEnvVar) Export

func (env *PosixEnvVar) Export(file string) error

export current enviroment string into specify file

func (*PosixEnvVar) Load

func (env *PosixEnvVar) Load(opt yocki.EnvVarLoadOpt) error

load exported env from disk

func (*PosixEnvVar) Print

func (env *PosixEnvVar) Print()

Print enviroment variable

func (*PosixEnvVar) SafeSet

func (env *PosixEnvVar) SafeSet(k string, v any) error

set global enviroment variable when key isn't exist

func (*PosixEnvVar) SafeSetL

func (env *PosixEnvVar) SafeSetL(k, v string) error

set local enviroment variable when key isn't exist

func (*PosixEnvVar) Set

func (env *PosixEnvVar) Set(k string, v any) error

set global enviroment variable

func (*PosixEnvVar) SetL

func (env *PosixEnvVar) SetL(k, v string) error

set local enviroment variable

func (*PosixEnvVar) SetPath

func (env *PosixEnvVar) SetPath(path string) error

SetPath set operate target: posix: /etc/enviroment, this only is empty method.

func (*PosixEnvVar) Unset

func (env *PosixEnvVar) Unset(k string) error

unset (delete) global enviroment variable

Jump to

Keyboard shortcuts

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