
Research
2025 Report: Destructive Malware in Open Source Packages
Destructive malware is rising across open source registries, using delays and kill switches to wipe code, break builds, and disrupt CI/CD.
import "github.com/tmc/inj"
Package inj provides a simple mechanism of dependency injection
It combines a type to value map and the capability of invoking a function with parameters supplied based on their types.
Example:
i := inj.New()
i.Register("foobar")
i.Register(42)
vals, _ := i.Call(func(a int, b string) string {
return fmt.Sprintf("%T:%v %T:%v", a, a, b, b)
})
fmt.Print(vals)
// Output:
// [int:42 string:foobar]
var (
// ErrNotFunc is returned by Call() if the provided value is not a function
ErrNotFunc = errors.New("inj: Provided value is not a function")
// ErrNotInterface is returned by RegisterAs() if the second argument is not an interface type
ErrNotInterface = errors.New("inj: Provided value is not an interface type")
// ErrDoesntImplement is returned by RegisterAs() if the first argument does not implement the second argument
ErrDoesntImplement = errors.New("inj: Provided value does not satisfy provided interface")
)
type Injector map[reflect.Type]reflect.Value
Injector is the type to value mapping that is utilized when looking up parameters in Call()
func New() Injector
New prepares a new Injector
func (inj Injector) Call(fun interface{}) ([]reflect.Value, error)
Call invokes fun with parameters populated by registered types
func (inj Injector) Register(value interface{}) (replaced bool)
Register provides a new implementation for a provided type
Returns true if this registration is replacing a previous registration
func (inj Injector) RegisterAs(value interface{}, registeredType interface{}) (bool, error)
RegisterAs provides a new implementation for a provided type but attempts to register it as the interface type registeredType. registeredType must be supplied as a pointer to the interface type.
Returns true if this registration is replacing a previous registration. Returns an error if the second argument isn't an interface or the first argument doesn't satisify the second.
Example:
i := inj.New()
i.RegisterAs(os.Stdin, (*io.Reader)(nil))
FAQs
Unknown package
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Research
Destructive malware is rising across open source registries, using delays and kill switches to wipe code, break builds, and disrupt CI/CD.

Security News
Socket CTO Ahmad Nassri shares practical AI coding techniques, tools, and team workflows, plus what still feels noisy and why shipping remains human-led.

Research
/Security News
A five-month operation turned 27 npm packages into durable hosting for browser-run lures that mimic document-sharing portals and Microsoft sign-in, targeting 25 organizations across manufacturing, industrial automation, plastics, and healthcare for credential theft.