persist

package module
v0.0.0-...-9bdd97c Latest Latest
Warning

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

Go to latest
Published: May 20, 2021 License: MIT Imports: 3 Imported by: 2

README

persist GoDoc

Persist loads and saves Go objects to files

Usage

First get it:

go get github.com/keks/persist

Then save objects like this:

var conf Config
f, err := os.Create("./project.conf")
if err != nil {
	log.Faralln("failed opening the persistent file:", err)
}

if err = persist.Save(f, &conf); err != nil {
	log.Fatalln("failed to save config:", err)
}

And load them like this:

// f is still in scope

var conf Config
if err := persist.Load(f, &conf); err != nil {
	log.Fatalln("failed to load config:", err)
}

Documentation

Overview

Package persist loads and saves Go objects to files.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Load

func Load(f *os.File, v interface{}) error

Load loads the file at path into v. Use os.IsNotExist() to see if the returned error is due to the file being missing.

func Save

func Save(f *os.File, v interface{}) error

Save saves a representation of v to the file at path.

Types

This section is empty.

Jump to

Keyboard shortcuts

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