Installing godi

Get up and running in 30 seconds.

Requirements

  • Go 1.21 or later

  • That’s it!

Install

go get github.com/junioryono/godi

Verify Installation

Create main.go:

package main

import (
    "fmt"
    "github.com/junioryono/godi/v2"
)

func main() {
    // Create a simple module
    appModule := godi.NewModule("app",
        godi.AddSingleton(func() string {
            return "Hello from godi!"
        }),
    )

    // Build container
    services := godi.NewServiceCollection()
    services.AddModules(appModule)

    provider, _ := services.BuildServiceProvider()
    defer provider.Close()

    // Use it
    message, _ := godi.Resolve[string](provider)
    fmt.Println(message)
}

Run it:

go run main.go
# Output: Hello from godi!

Success! You’re ready to use godi.

What’s Next?

Troubleshooting

“Module not found”

Make sure you’re in a Go module:

go mod init myapp
go get github.com/junioryono/godi

“Cannot find package”

Update your Go version:

go version  # Should be 1.21+

IDE not recognizing godi

Restart your IDE after installation, or run:

go mod download

That’s all! godi has zero runtime dependencies (except the excellent dig which is included).