goof

package module
v0.0.0-...-f1d11ca Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 28, 2024 License: Apache-2.0 Imports: 17 Imported by: 1 module, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Goof

Goof lets you call functions in your binary with just the string of their name. How?

var troop goof.Troop
out, err := troop.Call("fmt.Fprintf", os.Stdout, "hello %s", []interface{}{"world"})
if err != nil { // some error calling the function
	return err
}
n, err := out[0].(int), out[1].(error)
if err != nil {
	return err
}
fmt.Printf("wrote %d bytes\n", n)

Caveat: you have to have called fmt.Fprintf elsewhere in your binary.

Goof lets you get access to globals in your binary with just the string of their name. How?

var troop goof.Troop
rv, err := troop.Global("net/http.DefaultServeMux")
if err != nil { // couldn't find it
	return err
}
// rv contains an addressable reflect.Value of the default ServeMux!

Caveat: the global must be used elsewhere in the binary somehow.

Goof lets you get access to all of the reflect.Types in your binary. How?

var troop goof.Troop
types, err := troop.Types()
if err != nil { // something went wrong getting them
	return err
}
for _, typ := range types {
	fmt.Println(typ)
}

Caveat: the types must be possible outputs to reflect.TypeOf(val) in your binary.

Usage

You should probably just make a single Troop in your binary and use that everywhere since it does a lot of caching and work on first use.

How?

It loads up the dwarf information of any binary it's loaded in and then does a bunch of unsafe tom foolery to perform these dirty deeds. How unsafe is it?

  • Reusing needles unsafe.
  • Jumping into a shark tank with a steak swimming suit unsafe.
  • Carnival ride unsafe.
  • Driving on the wrong side of the highway blindfolded unsafe.

Should I use this?

Do you really have to ask? OF COURSE! If you do, please let me know what terrible idea this enabled. I'm very interested.

Testimonials

"I can't wait to get some goof in my manhole!" - @jtolds

"README is hilarious 😂"

"Now I just need to come up with something horrendously risky to use this for..."

Documentation

Overview

package goof is something you should never import.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Troop

type Troop struct {
	// contains filtered or unexported fields
}

func (*Troop) Call

func (t *Troop) Call(name string, args ...interface{}) ([]interface{}, error)

func (*Troop) Functions

func (t *Troop) Functions() ([]string, error)

func (*Troop) Global

func (t *Troop) Global(name string) (reflect.Value, error)

func (*Troop) Globals

func (t *Troop) Globals() ([]string, error)

func (*Troop) Type

func (t *Troop) Type(name string) (reflect.Type, error)

func (*Troop) Types

func (t *Troop) Types() ([]reflect.Type, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址