
Security News
Open Source Maintainers Feeling the Weight of the EU’s Cyber Resilience Act
The EU Cyber Resilience Act is prompting compliance requests that open source maintainers may not be obligated or equipped to handle.
github.com/lab210-dev/depkit
This package provides a simple way to manage dependencies in a Go application. It allows you to register and retrieve dependencies using Go interfaces.
It simplifies the process of writing unit tests by providing a simple and easy-to-use interface for managing dependencies between different components of your application. It allows you to register dependencies and callbacks, and retrieve them whenever needed, making it easy to test your code in isolation. This results in more maintainable and reliable tests, as well as a faster development process.
To install this package, use the go get
command:
go get github.com/kitstack/depkit
To use this package, you must first register your dependency using the Register function :
package example
import "github.com/kitstack/depkit"
type MyService interface {
DoSomething()
}
type myServiceImpl struct{}
func (s *myServiceImpl) DoSomething() {
// Do something here...
}
func init() {
depkit.Register[MyService](new(myServiceImpl))
}
You can now retrieve your service using the Get
function :
package example
import "github.com/kitstack/depkit"
type MyService interface {
DoSomething()
}
func main() {
depkit.Get[MyService]().DoSomething()
}
You can also use the GetAfterRegister function to execute a callback once the service has been registered :
package example
import "github.com/kitstack/depkit"
type MyService interface {
DoSomething()
}
func main() {
depkit.GetAfterRegister[MyService](func(s MyService) {
s.DoSomething()
})
}
To reset all registered dependencies, use the Reset function :
package example
import "github.com/kitstack/depkit"
func main() {
depkit.Reset()
}
goos: darwin
goarch: arm64
pkg: github.com/kitstack/depkit
BenchmarkGet
BenchmarkGet-10 6689894 167.8 ns/op
BenchmarkGetAfterRegister
BenchmarkGetAfterRegister-10 5415369 223.7 ns/op
Contributors to the package are encouraged to help improve the code.
If you have any questions or comments, don't hesitate to contact me.
I hope this package is helpful to you !
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.
Security News
The EU Cyber Resilience Act is prompting compliance requests that open source maintainers may not be obligated or equipped to handle.
Security News
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
Research
/Security News
Undocumented protestware found in 28 npm packages disrupts UI for Russian-language users visiting Russian and Belarusian domains.