generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: refactor go-runtime build (#2745)
this file was becoming difficult to reason with, particularly in regards to generating imports in the scaffolded files fixes redundancies and unifies the logic for generating imports across the various sources that may require importing. also ensures everything goes through the logic @matt2e added to avoid import conflicts
- Loading branch information
Showing
3 changed files
with
445 additions
and
433 deletions.
There are no files selected for viewing
42 changes: 16 additions & 26 deletions
42
go-runtime/compile/build-template/.ftl.tmpl/go/main/main.go.tmpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,47 @@ | ||
{{- $verbs := .Verbs -}} | ||
{{- $name := .Name -}} | ||
{{- with .MainCtx -}} | ||
|
||
// Code generated by FTL. DO NOT EDIT. | ||
package main | ||
|
||
import ( | ||
"context" | ||
|
||
{{- range .ExternalTypes }} | ||
|
||
{{.Import}} | ||
{{- end}} | ||
|
||
"github.com/TBD54566975/ftl/backend/protos/xyz/block/ftl/v1/ftlv1connect" | ||
"github.com/TBD54566975/ftl/common/plugin" | ||
{{- if or .SumTypes .ExternalTypes }} | ||
"github.com/TBD54566975/ftl/go-runtime/ftl/reflection" | ||
{{- end }} | ||
"github.com/TBD54566975/ftl/go-runtime/server" | ||
{{ range mainImports . }} | ||
"ftl/{{.}}" | ||
{{- range .Imports }} | ||
{{.}} | ||
{{- end}} | ||
) | ||
{{- if or .SumTypes .ExternalTypes }} | ||
|
||
func init() { | ||
reflection.Register( | ||
{{- range .SumTypes}} | ||
reflection.SumType[{{.Discriminator}}]( | ||
reflection.SumType[{{.TypeName}}]( | ||
{{- range .Variants}} | ||
*new({{.Name}}), | ||
{{- end}} | ||
), | ||
{{- end}} | ||
{{- range .ExternalTypes}} | ||
{{- range .Types}} | ||
reflection.ExternalType(*new({{.}})), | ||
{{- end}} | ||
reflection.ExternalType(*new({{.TypeName}})), | ||
{{- end}} | ||
) | ||
} | ||
{{- end}} | ||
|
||
func main() { | ||
verbConstructor := server.NewUserVerbServer("{{.ProjectName}}", "{{.Name}}", | ||
{{- range .Verbs}} | ||
verbConstructor := server.NewUserVerbServer("{{.ProjectName}}", "{{$name}}", | ||
{{- range $verbs }} | ||
{{- if and .HasRequest .HasResponse}} | ||
server.HandleCall({{.Package}}.{{.Name}}), | ||
server.HandleCall({{.TypeName}}), | ||
{{- else if .HasRequest}} | ||
server.HandleSink({{.Package}}.{{.Name}}), | ||
server.HandleSink({{.TypeName}}), | ||
{{- else if .HasResponse}} | ||
server.HandleSource({{.Package}}.{{.Name}}), | ||
server.HandleSource({{.TypeName}}), | ||
{{- else}} | ||
server.HandleEmpty({{.Package}}.{{.Name}}), | ||
server.HandleEmpty({{.TypeName}}), | ||
{{- end}} | ||
{{- end}} | ||
) | ||
plugin.Start(context.Background(), "{{.Name}}", verbConstructor, ftlv1connect.VerbServiceName, ftlv1connect.NewVerbServiceHandler) | ||
plugin.Start(context.Background(), "{{$name}}", verbConstructor, ftlv1connect.VerbServiceName, ftlv1connect.NewVerbServiceHandler) | ||
} | ||
{{- end -}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,33 @@ | ||
{{- $moduleName := .Name -}} | ||
{{- $verbs := .Verbs -}} | ||
{{- $name := .Name -}} | ||
{{- with .TypesCtx -}} | ||
|
||
// Code generated by FTL. DO NOT EDIT. | ||
package {{.Name}} | ||
|
||
{{- if or .LocalSumTypes .ExternalTypes }} | ||
package {{$name}} | ||
|
||
{{- if or .SumTypes .ExternalTypes }} | ||
{{ if .Imports -}} | ||
import ( | ||
{{- range .ExternalTypes }} | ||
{{.Import}} | ||
{{end}} | ||
"github.com/TBD54566975/ftl/go-runtime/ftl/reflection" | ||
|
||
{{ range typesImports . }} | ||
"{{.}}" | ||
{{- end}} | ||
{{- range .Imports }} | ||
{{.}} | ||
{{- end }} | ||
) | ||
{{- end }} | ||
|
||
func init() { | ||
reflection.Register( | ||
{{- range .LocalSumTypes}} | ||
reflection.SumType[{{ trimModuleQualifier $moduleName .Discriminator }}]( | ||
{{- range .SumTypes}} | ||
reflection.SumType[{{ trimModuleQualifier $moduleName .TypeName }}]( | ||
{{- range .Variants}} | ||
*new({{ trimModuleQualifier $moduleName .Name }}), | ||
{{- end}} | ||
), | ||
{{- end}} | ||
{{- range .ExternalTypes}} | ||
{{- range .Types}} | ||
reflection.ExternalType(*new({{.}})), | ||
{{- end}} | ||
reflection.ExternalType(*new({{.TypeName}})), | ||
{{- end}} | ||
) | ||
} | ||
{{- end}} | ||
{{- end -}} | ||
{{- end -}} |
Oops, something went wrong.