Go Lang Example - JSON Example1

import "encoding/json"

func JsonEncoder() {
	inputMsg := TEST_JSON{First_name: "ALEX"}

	//JSON Encoding
	jsonBytes, err := json.Marshal(inputMsg)
	fmt.Println(jsonBytes)
	if err != nil {
		panic(err)
	}

	// JSON 인코딩값 = jsonString
	jsonString := string(jsonBytes)
	fmt.Println(jsonString)
	fmt.Fprint(w, jsonString)
}

Go Lang Example - JSON Example 2

참고자료 : http://pyrasis.com/book/GoForTheReallyImpatient/Unit51

func API_CreateKey(w http.ResponseWriter, r *http.Request) {
	pubKey, priKey := GenerateKey()

	data := make(map[string]interface{})

	data["PublicKey"] = pubKey
	data["PrivateKey"] = priKey

	doc, _ := json.Marshal(data)
	fmt.Println(string(doc))
}

Output : {"prikey":"4APj8X5MZgSabt3XG5bheMfjEAyQmbTHHMbmwoZK4mUKecwmp814gCkUUnw6FidpcWEGAX3NWqb4ctFjGtRSk8Pb","pubkey":"2J3aTowM2hWvAxnzqmjD2u4z1jqvjmHgb12gGxETrzc9"}