add single_file_tests
This commit is contained in:
24
single_file_tests/json.go
Normal file
24
single_file_tests/json.go
Normal 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))
|
||||||
|
}
|
||||||
18
single_file_tests/reflect.go
Normal file
18
single_file_tests/reflect.go
Normal 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)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user