github.com/gogf/gf@v1.16.9/.example/os/gcache/note_interface_value.go (about)

     1  package main
     2  
     3  import (
     4  	"fmt"
     5  	"github.com/gogf/gf/os/gcache"
     6  	"github.com/gogf/gf/os/gctx"
     7  )
     8  
     9  func main() {
    10  	type User struct {
    11  		Id   int
    12  		Name string
    13  		Site string
    14  	}
    15  	var (
    16  		ctx   = gctx.New()
    17  		user  *User
    18  		key   = `UserKey`
    19  		value = &User{
    20  			Id:   1,
    21  			Name: "GoFrame",
    22  			Site: "https://goframe.org",
    23  		}
    24  	)
    25  	_ = gcache.Ctx(ctx).Set(key, value, 0)
    26  	v, _ := gcache.Ctx(ctx).GetVar(key)
    27  	_ = v.Scan(&user)
    28  	fmt.Printf(`%#v`, user)
    29  }