Skip to content

Commit

Permalink
feature: add yaml set Package (#17)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cq-z committed Feb 20, 2021
1 parent b162270 commit 832e079
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 1 deletion.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions dingotest/dingo.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
package: dingotest
services:
SendEmail:
type: '*SendEmail'
Expand Down
1 change: 1 addition & 0 deletions file.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
)

type File struct {
Package string
Services Services
fset *token.FileSet
file *ast.File
Expand Down
7 changes: 6 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 832e079

Please sign in to comment.