config

package
v0.0.0-...-f24390b Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2024 License: Apache-2.0 Imports: 12 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 ErrKeyNotExist error = errors.New("key does not exist")

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. At least that's how I understand it.

Types

type Config

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

Self-explanatory.

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 flushes 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. If there is an error, it will be of type *KeyError.

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) GobBytes

func (cfg *Config) GobBytes() []byte

GobBytes returns the actual gob-encoded data.

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 occurred.

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 KeyError

type KeyError struct {
	Op  string
	Key string
	Err error
}

func (*KeyError) Error

func (e *KeyError) Error() string

func (*KeyError) Unwrap

func (e *KeyError) Unwrap() error

type MapFunc

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

MapFunc represents a mapping function. It takes in a key and value and returns a new value.

Jump to

Keyboard shortcuts

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