config

package
v0.0.0-...-d13a3be Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package config implements a simple key-value store used to securely store game save data and high scores in a non-human readable binary format. It's basically a gob encoded map[string]interface{} .

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound error = errors.New("key not found")

Functions

func LoadDefaultOptions

func LoadDefaultOptions(cfg *Config)

func Register

func Register(value interface{})

Register simply calls gob.Register. If you are encoding a non-primitive type (like a struct or map) that implements something you should use this.

Types

type Config

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

func Create

func Create(path string, loadDefaults bool) (*Config, error)

Create creates a new Config.

func New

func New(path string, loadDefaults bool) (*Config, error)

New creates / opens and decodes a new Config.

func Open

func Open(path string) (*Config, error)

Open opens a existing Config.

func (*Config) Append

func (cfg *Config) Append(m map[string]interface{})

Append appends m to the map.

func (*Config) Close

func (cfg *Config) Close() error

Close simply calls (*os.File).Close and closes the file.

func (*Config) Data

func (cfg *Config) Data() map[string]interface{}

Data returns a copy of the map.

func (*Config) Delete

func (cfg *Config) Delete(key string)

Delete deletes key from the map.

func (*Config) Exists

func (cfg *Config) Exists(key string) bool

Exists checks if key exists.

func (*Config) Flush

func (cfg *Config) Flush() error

Flush gob encodes and writes data to the file.

func (*Config) Get

func (cfg *Config) Get(key string) (interface{}, error)

Get gets a value from the map.

func (*Config) GetWithFallback

func (cfg *Config) GetWithFallback(key string, fallback interface{}) interface{}

GetWithFallback gets a value from the map and returns the given fallback if not found.

func (*Config) Map

func (cfg *Config) Map(fn MapFunc)

Map iterates over the map and applies the MapFunc to every item.

func (*Config) MustGet

func (cfg *Config) MustGet(key string) interface{}

MustGet simply calls Get and returns nil if an error occured.

func (*Config) Set

func (cfg *Config) Set(key string, value interface{})

Set sets key to value.

func (*Config) SetData

func (cfg *Config) SetData(m map[string]interface{})

SetData overwrites the map.

func (*Config) Toggle

func (cfg *Config) Toggle(key string)

Toggle toggles a bool value.

func (*Config) Wipe

func (cfg *Config) Wipe()

Wipe wipes (clears) the map.

type MapFunc

type MapFunc func(string, interface{}) interface{}

Jump to

Keyboard shortcuts

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