gotostruct

package module
v0.0.0-...-1213329 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2015 License: MIT Imports: 8 Imported by: 1

README

License Build Status Go 1.3 Ready Go 1.4 Ready

GotoStruct

Open source Go package designed to help you converting JSON objects into Go Structs.

Examples

List of examples can be found within GotoStruct Examples.

Following code snippet:

package main

import (
	"fmt"
	gs "github.com/0x19/gotostruct"
	"strings"
)

func main() {
	gts := gs.GotoStruct{
		Name: "Example - Struct",
	}

	reader := strings.NewReader(`{"simple" : "json", "test": null, "something": [{"baz": 1}, {"baz": 2}]}`)

	response, err := gts.Generate(reader)

	if err != nil {
		fmt.Errorf("Got Error while generating struct: ", err)
	}

	fmt.Println(string(response))
}

will produce following struct:

type ExampleStruct struct {
	Simple    string `json:"simple"`
	Something []struct {
		Baz float64 `json:"baz"`
	} `json:"something"`
	Test interface{} `json:"test"`
}

Parts of GotoStruct code are taken from Json-to-struct.

Contributing

I encourage you to contribute to GotoStruct! Please check out the Contributing to GotoStruct for guidelines about how to proceed.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GotoStruct

type GotoStruct struct {
	Name string
}

func (*GotoStruct) Generate

func (g *GotoStruct) Generate(input io.Reader) ([]byte, error)

Func used for actual Struct generation. It must be type of io.Reader Name must be set by SetName() or on struct init.

func (*GotoStruct) SetName

func (g *GotoStruct) SetName(n string)

Just quick helper for naming. @TODO - Add some validation here and return error in case of issues

Jump to

Keyboard shortcuts

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