github.com/zeebo/goof@v0.0.0-20230907150950-e9457bc94477/README.md (about) 1 # Goof 2 3 Goof lets you call functions in your binary with just the string of their 4 name. How? 5 6 ```go 7 var troop goof.Troop 8 out, err := troop.Call("fmt.Fprintf", os.Stdout, "hello %s", []interface{}{"world"}) 9 if err != nil { // some error calling the function 10 return err 11 } 12 n, err := out[0].(int), out[1].(error) 13 if err != nil { 14 return err 15 } 16 fmt.Printf("wrote %d bytes\n", n) 17 ``` 18 19 Caveat: you have to have called `fmt.Fprintf` elsewhere in your binary. 20 21 Goof lets you get access to globals in your binary with just the string of 22 their name. How? 23 24 ```go 25 var troop goof.Troop 26 rv, err := troop.Global("net/http.DefaultServeMux") 27 if err != nil { // couldn't find it 28 return err 29 } 30 // rv contains an addressable reflect.Value of the default ServeMux! 31 ``` 32 33 Caveat: the global must be used elsewhere in the binary somehow. 34 35 Goof lets you get access to all of the `reflect.Type`s in your binary. How? 36 37 ```go 38 var troop goof.Troop 39 types, err := troop.Types() 40 if err != nil { // something went wrong getting them 41 return err 42 } 43 for _, typ := range types { 44 fmt.Println(typ) 45 } 46 ``` 47 48 Caveat: the types must be possible outputs to `reflect.TypeOf(val)` in your binary. 49 50 ## Usage 51 52 You should probably just make a single `Troop` in your binary and use that 53 everywhere since it does a lot of caching and work on first use. 54 55 ## How? 56 57 It loads up the dwarf information of any binary it's loaded in and then does 58 a bunch of unsafe tom foolery to perform these dirty deeds. How unsafe is it? 59 60 - Reusing needles unsafe. 61 - Jumping into a shark tank with a steak swimming suit unsafe. 62 - Carnival ride unsafe. 63 - Driving on the wrong side of the highway blindfolded unsafe. 64 65 ## Should I use this? 66 67 Do you really have to ask? OF COURSE! If you do, please let me know what terrible 68 idea this enabled. I'm very interested. 69 70 ## Testimonials 71 72 > "I can't wait to get some goof in my [manhole](https://github.com/jtolds/go-manhole)!" - [@jtolds](https://github.com/jtolds) 73 74 > "README is hilarious :joy:" 75 76 > "Now I just need to come up with something horrendously risky to use this for..."