tojson

package module
v0.0.0-...-08784bb Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2016 License: MIT Imports: 5 Imported by: 3 modules, 3 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

tojson package

Go Report Card

[GoDoc] (https://godoc.org/github.com/dns-gh/tojson)

Simple wrapper over the encoding/json package to save and load data into a file in json format

Motivation

Simplify a little bit the code for other projects.

Installation

  • It requires Go language of course. You can set it up by downloading it here: https://golang.org/dl/
  • Install it here C:/Go.
  • Set your GOPATH, GOROOT and PATH environment variables:
export GOROOT=C:/Go
export GOPATH=WORKING_DIR
export PATH=C:/Go/bin:${PATH}
  • Download and install the package:
@working_dir $ go get github.com/dns-gh/tojson/...
@working_dir $ go install github.com/dns-gh/tojson

Usage

package main

import "github.com/dns-gh/tojson"

type equipment struct {
	Weapon string `json:"weapon"`
	Shield string `json:"shield"`
}

func main() {
	oldEquipment := &equipment{
		Weapon: "sword",
		Shield: "wooden",
	}
	file := "equipment.json"
	tojson.Save(file, oldEquipment)
	newEquipement := &equipment{}
	tojson.Load(file, newEquipement)
}

Tests

@working_dir $ go test -v github.com/dns-gh/tojson
=== RUN   TestSaveLoadJSON
--- PASS: TestSaveLoadJSON (0.00s)
PASS
ok      tojson  0.055s

LICENSE

See included LICENSE file.

Documentation

Overview

Package tojson allows the user to save and load data of go structs into a given file in json format.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Load

func Load(path string, data interface{}) error

Load load json formated data from a given file

func Save

func Save(path string, data interface{}) error

Save save data in json format into the given file

Types

This section is empty.

Jump to

Keyboard shortcuts

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