type Template struct {
   name string
   *parse.Tree
   *common
   leftDelim  string
   rightDelim string
}


type common struct {
   tmpl       map[string]*Template
   parseFuncs template.FuncMap
   execFuncs  map[string]reflect.Value
}


func TestDemo(t *testing.T) {
   tpl := template.New("Foo")
   p := (*Template)(unsafe.Pointer(tpl))
   p.name = "Bar" // 关键在这里,突破私有成员
   logger.Debug("%v:%v", p, tpl)
}

输出结果

&{Bar } &{Bar }

t.name 也变成 Bar了, 成功突破template.Template私有字段 name



blog comments powered by Disqus

Published

2016-02-24

Categories


Tags