Jim's Blog
Toggle navigation
Jim's Blog
Home
About Me
Archives
Tags
Use unexported variables/functions in Golang
2017-12-24 07:23:20
644
0
0
jim
# Use unexported variables ## The unexported variables `unexport/i.go` ``` package unexport var i int func init() { i = 2 } ``` ## The new variables points the unexported variables `main.go` ``` package main import ( "fmt" _ "unsafe" _ "unexport" ) //go:linkname I unexport.i var I int func main() { fmt.Println(I) } ``` # Use unexported functions ``` package main import ( "fmt" "github.com/alangpierce/go-forceexport" ) func main() { var timeNow func() (int64, int32) err := forceexport.GetFunc(&timeNow, "time.now") if err != nil { // Handle errors if you care about name possibly being invalid. fmt.Println(err) } // Calls the actual time.now function. sec, nsec := timeNow() fmt.Printf("%v %v", sec, nsec) } ```
Pre:
openssl 生成自签证书及查看证书细节
Next:
Tcpdump advanced filters
0
likes
644
新浪微博
微信
腾讯微博
QQ空间
人人网
Please enable JavaScript to view the
comments powered by Disqus.
comments powered by
Disqus
Table of content