Skip to content

A go library to simplify reading and writing to files

License

Notifications You must be signed in to change notification settings

JGLTechnologies/SimpleFiles

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SimpleFiles

SimpleFiles is a go library to make reading and writing to file easier. SimpleFiles uses a RWMutex to prevent errors when using a file in multiple goroutines.


go get github.com/JGLTechnologies/SimpleFiles

Reading JSON from a file

package main

import (
	"fmt"
	"github.com/JGLTechnologies/SimpleFiles"
)

func main() {
	var j map[string]interface{}
	// If the file does not exist it will be created.
	f, err := SimpleFiles.New("test.json")
	if err != nil {
		panic(err)
	} else {
		err := f.ReadJSON(&j)
		if err != nil {
			panic(err)
		} else {
			fmt.Println(j["name"])
		}
	}
}

Writing JSON to a file

package main

import (
	"github.com/JGLTechnologies/SimpleFiles"
)

func main() {
	j := map[string]interface{}{"name": "Joe", "age": 47}
	// If the file does not exist it will be created.
	f, err := SimpleFiles.New("test.json")
	if err != nil {
		panic(err)
	} else {
		err := f.WriteJSON(j)
		if err != nil {
			panic(err)
		}
	}
}

About

A go library to simplify reading and writing to files

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages