Skip to content

Commit

Permalink
fix: fix broken FTL examples
Browse files Browse the repository at this point in the history
  • Loading branch information
wesbillman committed Feb 2, 2024
1 parent 7cc1d0b commit fc63fb8
Show file tree
Hide file tree
Showing 13 changed files with 99 additions and 79 deletions.
10 changes: 6 additions & 4 deletions FTL.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
"path": "kotlin-runtime"
},
{
"path": "examples/time"
"path": "examples/online-boutique"
},
{
"path": "examples/echo"
"path": "examples/go",
"name": "examples/go"
},
{
"path": "examples/online-boutique"
"path": "examples/kotlin",
"name": "examples/kotlin"
},
{
"path": "backend"
Expand Down Expand Up @@ -42,4 +44,4 @@
"**/*.zip": true,
}
}
}
}
3 changes: 1 addition & 2 deletions examples/echo/echo.go → examples/go/echo/echo.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,11 @@ type EchoResponse struct {
// Echo returns a greeting with the current time.
//
//ftl:verb
//ftl:ingress GET /echo
func Echo(ctx context.Context, req EchoRequest) (EchoResponse, error) {
fmt.Println("Echo received a request!")
tresp, err := sdk.Call(ctx, time.Time, time.TimeRequest{})
if err != nil {
return EchoResponse{}, err
}
return EchoResponse{Message: fmt.Sprintf("Hello, %s!!! It is %s!", req.Name.Default("anonymous"), tresp.Time)}, nil
return EchoResponse{Message: fmt.Sprintf("Hello, %s!!! It is %s!", req.Name.Default("anonymous"), tresp)}, nil
}
File renamed without changes.
27 changes: 17 additions & 10 deletions examples/echo/go.mod → examples/go/echo/go.mod
Original file line number Diff line number Diff line change
@@ -1,39 +1,46 @@
module ftl/echo

go 1.21.5
go 1.21.6

require github.com/TBD54566975/ftl v0.95.0
replace github.com/TBD54566975/ftl => ../../..

require github.com/TBD54566975/ftl v0.0.0-00010101000000-000000000000

require (
connectrpc.com/connect v1.14.0 // indirect
connectrpc.com/grpcreflect v1.2.0 // indirect
connectrpc.com/otelconnect v0.6.0 // indirect
connectrpc.com/otelconnect v0.7.0 // indirect
github.com/alecthomas/concurrency v0.0.2 // indirect
github.com/alecthomas/participle/v2 v2.1.1 // indirect
github.com/alecthomas/types v0.9.0 // indirect
github.com/alecthomas/types v0.10.1 // indirect
github.com/alessio/shellescape v1.4.2 // indirect
github.com/danieljoos/wincred v1.2.0 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/godbus/dbus/v5 v5.1.0 // indirect
github.com/google/uuid v1.5.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/iancoleman/strcase v0.2.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
github.com/jackc/pgx/v5 v5.5.2 // indirect
github.com/jackc/puddle/v2 v2.2.1 // indirect
github.com/jpillora/backoff v1.0.0 // indirect
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/oklog/ulid/v2 v2.1.0 // indirect
github.com/swaggest/jsonschema-go v0.3.64 // indirect
github.com/swaggest/refl v1.3.0 // indirect
github.com/zalando/go-keyring v0.2.3 // indirect
go.opentelemetry.io/otel v1.21.0 // indirect
go.opentelemetry.io/otel/metric v1.21.0 // indirect
go.opentelemetry.io/otel/trace v1.21.0 // indirect
go.opentelemetry.io/otel v1.22.0 // indirect
go.opentelemetry.io/otel/metric v1.22.0 // indirect
go.opentelemetry.io/otel/trace v1.22.0 // indirect
golang.design/x/reflect v0.0.0-20220504060917-02c43be63f3b // indirect
golang.org/x/crypto v0.18.0 // indirect
golang.org/x/exp v0.0.0-20231127185646-65229373498e // indirect
golang.org/x/mod v0.14.0 // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/net v0.20.0 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/protobuf v1.32.0 // indirect
)
66 changes: 40 additions & 26 deletions examples/echo/go.sum → examples/go/echo/go.sum

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

File renamed without changes.
5 changes: 5 additions & 0 deletions examples/go/time/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module ftl/time

go 1.21.6

replace github.com/TBD54566975/ftl => ../../..
File renamed without changes.
19 changes: 19 additions & 0 deletions examples/go/time/time.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//ftl:module time
package time

import (
"context"
"time"
)

type TimeRequest struct{}
type TimeResponse struct {
Time time.Time
}

// Time returns the current time.
//
//ftl:verb
func Time(ctx context.Context, req TimeRequest) (TimeResponse, error) {
return TimeResponse{Time: time.Now()}, nil
}
15 changes: 10 additions & 5 deletions examples/kotlin/ftl-module-ad/src/main/kotlin/ftl/ad/Ad.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ package ftl.ad

import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import ftl.builtin.HttpRequest
import ftl.builtin.HttpResponse
import xyz.block.ftl.Context
import xyz.block.ftl.Ingress
import xyz.block.ftl.Ingress.Type.HTTP
import xyz.block.ftl.Method
import xyz.block.ftl.Verb
import java.util.*
Expand All @@ -16,12 +19,14 @@ class AdModule {
private val database: Map<String, Ad> = loadDatabase()

@Verb
@Ingress(Method.GET, "/get")
fun get(context: Context, req: AdRequest): AdResponse {
return when {
req.contextKeys != null -> AdResponse(ads = contextualAds(req.contextKeys))
else -> AdResponse(ads = randomAds())
@Ingress(Method.GET, "/get", HTTP)
fun get(context: Context, req: HttpRequest<AdRequest>): HttpResponse<AdResponse> {
val ads: List<Ad> = when {
req.body.contextKeys != null -> contextualAds(req.body.contextKeys)
else -> randomAds()
}

return HttpResponse(status = 200, headers = emptyMap(), body = AdResponse(ads = ads))
}

private fun contextualAds(contextKeys: List<String>): List<Ad> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import ftl.time.TimeModuleClient
import ftl.time.TimeRequest
import xyz.block.ftl.Context
import xyz.block.ftl.Ingress
import xyz.block.ftl.Ingress.Type.HTTP
import xyz.block.ftl.Method
import xyz.block.ftl.Verb

Expand All @@ -15,7 +16,6 @@ data class EchoResponse(val message: String)
class Echo {
@Throws(InvalidInput::class)
@Verb
@Ingress(Method.GET, "/echo")
fun echo(context: Context, req: EchoRequest): EchoResponse {
val response = context.call(TimeModuleClient::time, TimeRequest)
return EchoResponse(message = "Hello, ${req.name ?: "anonymous"}! The time is ${response.time}.")
Expand Down
5 changes: 0 additions & 5 deletions examples/time/go.mod

This file was deleted.

26 changes: 0 additions & 26 deletions examples/time/time.go

This file was deleted.

0 comments on commit fc63fb8

Please sign in to comment.