Skip to content

Commit

Permalink
translation refactoring work in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
adranwit committed Jul 7, 2023
1 parent cef46f8 commit 1484376
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
6 changes: 5 additions & 1 deletion internal/codegen/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ func (t *Template) GenerateHandler(opts *options.Gen, info *plugin.Info) (string
handlerContent = strings.Replace(handlerContent, "$LocalVariable", localVariableDeclaration, 1)
registerTypes := t.RegisterFragment("Handler")
handlerContent = strings.Replace(handlerContent, "$RegisterTypes", registerTypes, 1)
handlerContent = strings.Replace(handlerContent, "$ChecksumImport", `"`+info.ChecksumPkg()+`"`, 1)
imports := NewImports()
imports.AddPackage(info.ChecksumPkg())
imports.AddPackage(info.TypeCorePkg())
imports.AddPackage("reflect")
handlerContent = strings.Replace(handlerContent, "$RawImports", imports.RawImports(), 1)

info.ChecksumPkg()
logic := builder.String()
Expand Down
13 changes: 11 additions & 2 deletions internal/codegen/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,22 @@ func (i *Imports) PackageImports() string {
}
builder := strings.Builder{}
builder.WriteString("\nimport (")
i.rawImports(builder)
builder.WriteByte(')')
return builder.String()
}

func (i *Imports) RawImports() string {
builder := strings.Builder{}
i.rawImports(builder)
return builder.String()
}
func (i *Imports) rawImports(builder strings.Builder) {
for _, item := range i.Packages {
builder.WriteString("\t\"")
builder.WriteString(item)
builder.WriteString("\"\n")
}
builder.WriteByte(')')
return builder.String()
}

func (i *Imports) DefaultPackageImports() string {
Expand Down
2 changes: 2 additions & 0 deletions internal/codegen/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ func (t *Template) GenerateState(pkg string, info *plugin.Info) string {
importFragment := ""
imports := NewImports()
imports.AddPackage(info.ChecksumPkg())
imports.AddPackage("reflect")
imports.AddPackage(info.TypeCorePkg())
switch info.IntegrationMode {
case plugin.ModeExtension, plugin.ModeCustomTypeModule:
importFragment = imports.PackageImports()
Expand Down
2 changes: 1 addition & 1 deletion internal/codegen/tmpl/handler/handler.gox
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package $Package
import (
"context"
"github.com/viant/xdatly/handler"
$ChecksumImport
$RawImports
)

func init() {
Expand Down

0 comments on commit 1484376

Please sign in to comment.