diff --git a/README.md b/README.md index 1341e7c..5948bd3 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,7 @@ Easy, fast and type-safe dependency injection for Go. * [Installation](#installation) * [Building the Container](#building-the-container) + * [Configuring Package](#configuring-package) * [Configuring Services](#configuring-services) + [arguments](#arguments) + [error](#error) @@ -54,6 +55,10 @@ services: It will generate a file called `dingo.go`. This must be committed with your code. +## Configuring Package +The root level `package` key describes the package name. + +Default is the directory name is not enough because it may contain a command (package main). Find the first non-test file to get the real package name. ## Configuring Services diff --git a/dingotest/dingo.yml b/dingotest/dingo.yml index b2aea7b..df4748c 100644 --- a/dingotest/dingo.yml +++ b/dingotest/dingo.yml @@ -1,3 +1,4 @@ +package: dingotest services: SendEmail: type: '*SendEmail' diff --git a/file.go b/file.go index 31905e4..9c436b8 100644 --- a/file.go +++ b/file.go @@ -13,6 +13,7 @@ import ( ) type File struct { + Package string Services Services fset *token.FileSet file *ast.File diff --git a/main.go b/main.go index b5686c6..02abeb2 100755 --- a/main.go +++ b/main.go @@ -32,7 +32,12 @@ func main() { if err != nil { log.Fatalln(err) } - packageName := file.getPackageName(dingoYMLPath) + + packageName := file.Package + if packageName == "" { + packageName = file.getPackageName(dingoYMLPath) + } + file, err = GenerateContainer(file, packageName, outputFile) if err != nil { log.Fatalln(err)