Skip to content

Commit

Permalink
refactor: remove ftl.Call
Browse files Browse the repository at this point in the history
  • Loading branch information
worstell committed Oct 1, 2024
1 parent b51e3b3 commit 4ed4c02
Show file tree
Hide file tree
Showing 50 changed files with 660 additions and 518 deletions.
1 change: 0 additions & 1 deletion docs/content/docs/reference/unittests.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ In this default set up, FTL does the following:
- prevents access to `ftl.ConfigValue` and `ftl.SecretValue` ([See options](#project-files-configs-and-secrets))
- prevents access to `ftl.Database` ([See options](#databases))
- prevents access to `ftl.MapHandle` ([See options](#maps))
- prevents calls via `ftl.Call(...)` ([See options](#calls))
- disables all subscribers ([See options](#pubsub))

## Customization
Expand Down
4 changes: 2 additions & 2 deletions examples/go/echo/echo.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ type EchoResponse struct {
// Echo returns a greeting with the current time.
//
//ftl:verb export
func Echo(ctx context.Context, req EchoRequest) (EchoResponse, error) {
tresp, err := ftl.Call(ctx, time.Time, time.TimeRequest{})
func Echo(ctx context.Context, req EchoRequest, tc time.TimeClient) (EchoResponse, error) {
tresp, err := tc(ctx, time.TimeRequest{})
if err != nil {
return EchoResponse{}, err
}
Expand Down
14 changes: 14 additions & 0 deletions examples/go/echo/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,19 @@ require (
github.com/XSAM/otelsql v0.34.0 // indirect
github.com/alecthomas/atomic v0.1.0-alpha2 // indirect
github.com/alecthomas/concurrency v0.0.2 // indirect
github.com/alecthomas/kong v1.2.1 // indirect
github.com/alecthomas/participle/v2 v2.1.1 // indirect
github.com/alecthomas/types v0.16.0 // indirect
github.com/alessio/shellescape v1.4.2 // indirect
github.com/benbjohnson/clock v1.3.5 // indirect
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/danieljoos/wincred v1.2.0 // indirect
github.com/deckarep/golang-set/v2 v2.6.0 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/godbus/dbus/v5 v5.1.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0 // indirect
github.com/hashicorp/cronexpr v1.1.2 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
Expand All @@ -36,14 +40,24 @@ require (
github.com/swaggest/refl v1.3.0 // indirect
github.com/zalando/go-keyring v0.2.5 // indirect
go.opentelemetry.io/otel v1.30.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.30.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.30.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.30.0 // indirect
go.opentelemetry.io/otel/metric v1.30.0 // indirect
go.opentelemetry.io/otel/sdk v1.30.0 // indirect
go.opentelemetry.io/otel/sdk/metric v1.30.0 // indirect
go.opentelemetry.io/otel/trace v1.30.0 // indirect
go.opentelemetry.io/proto/otlp v1.3.1 // indirect
go.uber.org/automaxprocs v1.6.0 // indirect
golang.org/x/crypto v0.27.0 // indirect
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 // indirect
golang.org/x/mod v0.21.0 // indirect
golang.org/x/net v0.29.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/sys v0.25.0 // indirect
golang.org/x/text v0.18.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240903143218-8af14fe29dc1 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1 // indirect
google.golang.org/grpc v1.66.2 // indirect
google.golang.org/protobuf v1.34.2 // indirect
)
24 changes: 24 additions & 0 deletions examples/go/echo/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 9 additions & 4 deletions examples/go/echo/types.ftl.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions frontend/cli/testdata/go/echo/echo.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ type EchoResponse struct {
// Echo returns a greeting with the current time.
//
//ftl:verb
func Echo(ctx context.Context, req EchoRequest) (EchoResponse, error) {
tresp, err := ftl.Call(ctx, time.Time, time.TimeRequest{})
func Echo(ctx context.Context, req EchoRequest, tc time.TimeClient) (EchoResponse, error) {
tresp, err := tc(ctx, time.TimeRequest{})
if err != nil {
return EchoResponse{}, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,15 @@ func init() {
{{.TypeName}},
{{- range .Resources}}
{{- with getVerbClient . }}
server.VerbClient[{{.TypeName}}, {{.Request.TypeName}}, {{.Response.TypeName}}](),
{{- if and (eq .Request.TypeName "ftl.Unit") (eq .Response.TypeName "ftl.Unit") }}
server.EmptyClient[{{.TypeName}}](),
{{- else if eq .Request.TypeName "ftl.Unit" }}
server.SourceClient[{{.TypeName}}, {{.Response.TypeName}}](),
{{- else if eq .Response.TypeName "ftl.Unit" }}
server.SinkClient[{{.TypeName}}, {{.Request.TypeName}}](),
{{- else }}
server.VerbClient[{{.TypeName}}, {{.Request.TypeName}}, {{.Response.TypeName}}](),
{{- end -}}
{{- end }}
{{- end}}
),
Expand Down
4 changes: 1 addition & 3 deletions go-runtime/compile/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -758,9 +758,7 @@ func (b *mainModuleContextBuilder) processVerb(verb *schema.Verb) (goVerb, error
}
calleeNativeName, ok := b.nativeNames[call]
if !ok {
// TODO: skip for now because metadata from legacy ftl.Call(...) will not have native name
continue
// return goVerb{}, fmt.Errorf("missing native name for verb client %s", call)
return goVerb{}, fmt.Errorf("missing native name for verb client %s", call)
}
calleeverb, err := b.getGoVerb(calleeNativeName, callee)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions go-runtime/compile/compile_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestNonExportedDecls(t *testing.T) {
in.CopyModule("notexportedverb"),
in.ExpectError(
in.ExecWithOutput("ftl", []string{"deploy", "notexportedverb"}, func(_ string) {}),
"call first argument must be a function but is an unresolved reference to echo.Echo, does it need to be exported?",
`unsupported verb parameter type &{"echo" "EchoClient"}; verbs must have the signature func(Context, Request?, Resources...)`,
),
)
}
Expand All @@ -34,7 +34,7 @@ func TestUndefinedExportedDecls(t *testing.T) {
in.CopyModule("undefinedverb"),
in.ExpectError(
in.ExecWithOutput("ftl", []string{"deploy", "undefinedverb"}, func(_ string) {}),
"call first argument must be a function but is an unresolved reference to echo.Undefined",
`unsupported verb parameter type &{"echo" "UndefinedClient"}; verbs must have the signature func(Context, Request?, Resources...)`,
),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,32 +60,12 @@ type {{.Name|title}}
{{- else if is "Verb" .}}
//ftl:verb
{{- if and (eq (type $.Module .Request) "ftl.Unit") (eq (type $.Module .Response) "ftl.Unit")}}
func {{.Name|title}}(context.Context) error {
panic("Verb stubs should not be called directly, instead use github.com/TBD54566975/ftl/runtime-go/ftl.CallEmpty()")
}

//ftl:verb
type {{.Name|title}}Client func(context.Context) error
{{- else if eq (type $.Module .Request) "ftl.Unit"}}
func {{.Name|title}}(context.Context) ({{type $.Module .Response}}, error) {
panic("Verb stubs should not be called directly, instead use github.com/TBD54566975/ftl/runtime-go/ftl.CallSource()")
}

//ftl:verb
type {{.Name|title}}Client func(context.Context) ({{type $.Module .Response}}, error)
{{- else if eq (type $.Module .Response) "ftl.Unit"}}
func {{.Name|title}}(context.Context, {{type $.Module .Request}}) error {
panic("Verb stubs should not be called directly, instead use github.com/TBD54566975/ftl/runtime-go/ftl.CallSink()")
}

//ftl:verb
type {{.Name|title}}Client func(context.Context, {{type $.Module .Request}})
{{- else}}
func {{.Name|title}}(context.Context, {{type $.Module .Request}}) ({{type $.Module .Response}}, error) {
panic("Verb stubs should not be called directly, instead use github.com/TBD54566975/ftl/runtime-go/ftl.Call()")
}

//ftl:verb
type {{.Name|title}}Client func(context.Context, {{type $.Module .Request}}) ({{type $.Module .Response}}, error)
{{- end}}
{{- end}}
Expand Down
4 changes: 2 additions & 2 deletions go-runtime/compile/testdata/go/echo/echo.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ type EchoResponse struct {
// Echo returns a greeting with the current time.
//
//ftl:verb
func Echo(ctx context.Context, req EchoRequest) (EchoResponse, error) {
tresp, err := ftl.Call(ctx, time.Time, time.TimeRequest{})
func Echo(ctx context.Context, req EchoRequest, tc time.TimeClient) (EchoResponse, error) {
tresp, err := tc(ctx, time.TimeRequest{})
if err != nil {
return EchoResponse{}, err
}
Expand Down
14 changes: 14 additions & 0 deletions go-runtime/compile/testdata/go/echo/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,19 @@ require (
github.com/XSAM/otelsql v0.34.0 // indirect
github.com/alecthomas/atomic v0.1.0-alpha2 // indirect
github.com/alecthomas/concurrency v0.0.2 // indirect
github.com/alecthomas/kong v1.2.1 // indirect
github.com/alecthomas/participle/v2 v2.1.1 // indirect
github.com/alecthomas/types v0.16.0 // indirect
github.com/alessio/shellescape v1.4.2 // indirect
github.com/benbjohnson/clock v1.3.5 // indirect
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/danieljoos/wincred v1.2.0 // indirect
github.com/deckarep/golang-set/v2 v2.6.0 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/godbus/dbus/v5 v5.1.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0 // indirect
github.com/hashicorp/cronexpr v1.1.2 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
Expand All @@ -36,14 +40,24 @@ require (
github.com/swaggest/refl v1.3.0 // indirect
github.com/zalando/go-keyring v0.2.5 // indirect
go.opentelemetry.io/otel v1.30.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.30.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.30.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.30.0 // indirect
go.opentelemetry.io/otel/metric v1.30.0 // indirect
go.opentelemetry.io/otel/sdk v1.30.0 // indirect
go.opentelemetry.io/otel/sdk/metric v1.30.0 // indirect
go.opentelemetry.io/otel/trace v1.30.0 // indirect
go.opentelemetry.io/proto/otlp v1.3.1 // indirect
go.uber.org/automaxprocs v1.6.0 // indirect
golang.org/x/crypto v0.27.0 // indirect
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 // indirect
golang.org/x/mod v0.21.0 // indirect
golang.org/x/net v0.29.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/sys v0.25.0 // indirect
golang.org/x/text v0.18.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240903143218-8af14fe29dc1 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1 // indirect
google.golang.org/grpc v1.66.2 // indirect
google.golang.org/protobuf v1.34.2 // indirect
)
Loading

0 comments on commit 4ed4c02

Please sign in to comment.