add single_file_tests

This commit is contained in:
2020-02-09 23:53:57 +08:00
parent 2bbe3a6575
commit d60039deac
2 changed files with 42 additions and 0 deletions

24
single_file_tests/json.go Normal file
View File

@@ -0,0 +1,24 @@
package main
import (
"encoding/json"
"fmt"
)
type Test struct {
Name string `json:"name"`
Age int32 `json:"age"`
}
func main() {
t := Test {
Name: "hatter",
Age: 18,
}
s, err := json.Marshal(t)
if err != nil {
fmt.Println("ERROR: ", err)
return
}
fmt.Println("JSON: ", string(s))
}

View File

@@ -0,0 +1,18 @@
package main
import (
"fmt"
)
func main() {
var x interface{} = "str"
switch t := x.(type) {
case string:
fmt.Println("String!")
s := x.(string)
fmt.Println("As string: " + s)
default:
fmt.Println("Other: ", t)
}
}