github.com/gogf/gf@v1.16.9/.example/util/gconv/gconv_map1.go (about)

     1  package main
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/gogf/gf/util/gconv"
     7  )
     8  
     9  func main() {
    10  	type User struct {
    11  		Uid  int    `json:"uid"`
    12  		Name string `json:"name"`
    13  	}
    14  	// 对象
    15  	fmt.Println(gconv.Map(User{
    16  		Uid:  1,
    17  		Name: "john",
    18  	}))
    19  	// 对象指针
    20  	fmt.Println(gconv.Map(&User{
    21  		Uid:  1,
    22  		Name: "john",
    23  	}))
    24  
    25  	// 任意map类型
    26  	fmt.Println(gconv.Map(map[int]int{
    27  		100: 10000,
    28  	}))
    29  }