package
0.0.0-20220323031208-a99fd5a1d443
Repository: https://github.com/iskraman/golang-modules.git
Documentation: pkg.go.dev

# README

golang-modules/jsonlib

Golang Json 모듈화

func Encoding

Go data to JSON message encoding

func Encoding(v interface{}) ([]byte, error)

(example)  
type User struct {  
	string `json:"name"`  
	Age  int    `json:"age,omitempty"`  
}  

var u1 = User{Name: "iskra", Age: 10}  
enc, _ := jsonlib.Encoding(u1)  
fmt.Println(string(enc))  

func EncodingIndent

Go data to JSON cute message encoding

func EncodingIndent(v interface{}) ([]byte, error)

(example)
enc, _ := jsonlib.EncodingIndent(u1)

func EncodingStream

Go data to JSON stream encoding

func EncodingStream(w io.Writer, v interface{}) error

(example)
jsonlib.EncodingStream(os.Stdout, u1)

(output : stdout)
{"name":"iskra","age":10}

func EncodingIndentStream

Go data to JSON cute stream encoding

func EncodingIndentStream(w io.Writer, v interface{}) error

(example)
wfd, _ := os.Create("out.txt")
jsonlib.EncodingIndentStream(wfd, u1)
wfd.Close()

(output : "out.txt")
{
	"name": "iskra",
	"age": 10
}

func Decoding

JSON to Go data decoding

func Decoding(data []byte, v interface{}) error

(example)
u2 := User{}
jsonlib.Decoding(enc, &u2)
fmt.Printf(%+v\n", u2)

func DecodingStream

JSON to Go data stream decoding

func DecodingStream(r io.Reader, v interface{}) error

(example)
u3 := User{}
rfd, _ := os.Open("out.txt")
jsonlib.DecodingStream(rfd, &u3)
fmt.Printf("DecodingStream: %+v\n", u3)
rfd.Close()

func DecodingMap

JSON to Go Map decoding

func DecodingMap(data []byte, v *map[string]interface{}) error

(example)
var reading map[string]interface{}
jsonlib.DecodingMap(enc, &reading)
fmt.Printf("%+v\n", reading)
fmt.Println(reading["name"], reading["age"])

# Functions

Json -> Memory.
No description provided by the author
No description provided by the author
Memory -> Json.
No description provided by the author
No description provided by the author
Memory -> IO Stream.