Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "encoding/json"
- "fmt"
- "reflect"
- )
- // Common s
- type Common struct {
- Name string `json:"name"`
- Config interface{} `json:"config"`
- }
- // PodConf s
- type PodConf struct {
- ID string `json:"id"`
- }
- func getConf() interface{} {
- //var c *PodConf
- //return c
- return new(PodConf)
- }
- func main() {
- data := []byte(`{"name":"kek","config":{"id":"keklelel"}}`)
- c := Common{
- Config: getConf(),
- }
- rv := reflect.ValueOf(&c)
- fmt.Println(rv.Elem().Kind())
- rv = rv.Elem()
- fmt.Println(rv)
- switch c.Config.(type) {
- case *PodConf:
- fmt.Println("podconf")
- default:
- fmt.Println("kek")
- }
- err := json.Unmarshal(data, &c)
- if err != nil {
- fmt.Println(err)
- }
- fmt.Println(c, c.Config)
- switch c.Config.(type) {
- case *PodConf:
- fmt.Println("podconf")
- default:
- fmt.Println("kek")
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement