Skip to content

jasonmoo/funsafe

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

#funsafe

Experimental package for unsetting the read-only flags from reflect.Values, bypassing package export guarantees.

Example:

//
// package private
//
// type Example struct {
//     a int
// }

func main() {

	v := &private.Example{}

	fmt.Printf("%#v\n", v) // &private.Example{a:0}

	av := reflect.ValueOf(v).Elem().FieldByName("a")

	funsafe.MakeSettable(&av)

	av.SetInt(1)

	fmt.Printf("%#v\n", v) // &private.Example{a:1}

}

For research only. Violating package scoping guarantees is the wrong approach for production code. However it can produce some interesting opportunities for toying with the go stdlib and other imported packages. Use at your own risk!

LICENSE: MIT

About

experimental package for bypassing package export rules in go

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages