Skip to content

Commit

Permalink
Merge pull request #155 from sublee/default-config-variables
Browse files Browse the repository at this point in the history
Enable goverter:enum on goverter:variables mode
  • Loading branch information
jmattheis authored Aug 9, 2024
2 parents b046455 + efefb02 commit 551dbe9
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 4 deletions.
5 changes: 1 addition & 4 deletions config/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,12 @@ func initConverter(loader *pkgload.PackageLoader, rawConverter *RawConverter) (*
return nil, err
}

c.OutputFile = "./generated/generated.go"
c.OutputPackageName = "generated"
c.typ = v.Type()
c.Name = rawConverter.InterfaceName + "Impl"
c.OutputFormat = FormatStruct
return c, nil
}

c.OutputFormat = FormatVariable
c.ConverterConfig = DefaultConfigVariables
c.OutputFile = defaultOutputFile(rawConverter.FileName)
c.OutputPackageName = rawConverter.PackageName
c.OutputPackagePath = rawConverter.PackagePath
Expand Down
44 changes: 44 additions & 0 deletions scenario/var_enum.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
input:
input.go: |
package example
type Enum1 int
type Enum2 string
const (
Enum1A Enum1 = iota
Enum1B
)
const (
Enum2A Enum2 = "A"
Enum2B Enum2 = "B"
)
// goverter:variables
var (
// goverter:enum:unknown Enum2A
// goverter:enum:map Enum1A Enum2A
// goverter:enum:map Enum1B Enum2B
Convert func(Enum1) Enum2
)
success:
- input.gen.go: |
// Code generated by github.com/jmattheis/goverter, DO NOT EDIT.
package example
func init() {
Convert = func(source Enum1) Enum2 {
var exampleEnum2 Enum2
switch source {
case Enum1A:
exampleEnum2 = Enum2A
case Enum1B:
exampleEnum2 = Enum2B
default:
exampleEnum2 = Enum2A
}
return exampleEnum2
}
}

0 comments on commit 551dbe9

Please sign in to comment.