mirror of https://github.com/tinygo-org/tinygo.git
wasmstm32webassemblymicrocontrollerarmavrspiwasiadafruitarduinocircuitplayground-expressgpioi2cllvmmicrobitnrf51nrf52nrf52840samd21tinygo
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
21 lines
380 B
21 lines
380 B
4 years ago
|
package main
|
||
|
|
||
|
import (
|
||
|
"encoding/json"
|
||
|
)
|
||
|
|
||
|
func main() {
|
||
|
println("int:", encode(3))
|
||
|
println("float64:", encode(3.14))
|
||
|
println("string:", encode("foo"))
|
||
|
println("slice of strings:", encode([]string{"foo", "bar"}))
|
||
|
}
|
||
|
|
||
|
func encode(itf interface{}) string {
|
||
|
buf, err := json.Marshal(itf)
|
||
|
if err != nil {
|
||
|
panic("failed to JSON encode: " + err.Error())
|
||
|
}
|
||
|
return string(buf)
|
||
|
}
|