go-gen-root

command module
v0.0.0-...-688e664 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2024 License: MIT Imports: 5 Imported by: 0

README

go-gen-root

A simple example of an automated composition root generator for Go projects.

Usage

  • Install the tool
    • go install -v github.com/sealbro/go-gen-root@latest
  • Add @inject comment to your struct constructor function
    • Function must return only reference from struct instance
  • Run generator with next parameters as example
    • go-gen-root generate -p examples/app-with-deps -m github.com/sealbro/go-gen-root -o examples/app-with-deps/cmd/app/di.go

Features

  • Generate composition root App struct
  • Sorted variables from zero parameter to many
  • Throw panic if constructor function has not injected parameters
  • Register interface as declaration and bind with reference, additionally check if interface is implemented
  • Use instances initializes manually and register them in App struct
  • Return error from constructor function and correctly handle it
  • Configure generator tool with flags (module name, output path, package name)

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
examples
internal
ast

Jump to

Keyboard shortcuts

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