generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: redesign kotlin verb interface (#916)
fixes #803 with this change, verbs in kotlin are defined as top-level functions rather than class member functions
- Loading branch information
Showing
22 changed files
with
670 additions
and
683 deletions.
There are no files selected for viewing
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
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
17 changes: 7 additions & 10 deletions
17
examples/kotlin/ftl-module-echo/src/main/kotlin/ftl/echo/Echo.kt
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,21 +1,18 @@ | ||
package ftl.echo | ||
|
||
import ftl.time.TimeModuleClient | ||
import ftl.time.TimeRequest | ||
import ftl.builtin.Empty | ||
import ftl.time.time | ||
import xyz.block.ftl.Context | ||
import xyz.block.ftl.Method | ||
import xyz.block.ftl.Verb | ||
|
||
class InvalidInput(val field: String) : Exception() | ||
|
||
data class EchoRequest(val name: String?) | ||
data class EchoResponse(val message: String) | ||
|
||
class Echo { | ||
@Throws(InvalidInput::class) | ||
@Verb | ||
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}.") | ||
} | ||
@Throws(InvalidInput::class) | ||
@Verb | ||
fun echo(context: Context, req: EchoRequest): EchoResponse { | ||
val response = context.call(::time, Empty()) | ||
return EchoResponse(message = "Hello, ${req.name ?: "anonymous"}! The time is ${response.time}.") | ||
} |
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
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,21 +1,19 @@ | ||
package ftl.echo | ||
|
||
import ftl.echo2.Echo2ModuleClient | ||
import ftl.echo2.echo as echo2 | ||
import xyz.block.ftl.Context | ||
import xyz.block.ftl.Verb | ||
|
||
data class EchoRequest(val name: String) | ||
data class EchoResponse(val message: String) | ||
|
||
class Echo { | ||
@Verb | ||
fun echo(context: Context, req: EchoRequest): EchoResponse { | ||
return EchoResponse(message = "Hello, ${req.name}!") | ||
} | ||
@Verb | ||
fun echo(context: Context, req: EchoRequest): EchoResponse { | ||
return EchoResponse(message = "Hello, ${req.name}!") | ||
} | ||
|
||
@Verb | ||
fun call(context: Context, req: EchoRequest): EchoResponse { | ||
val res = context.call(Echo2ModuleClient::echo, ftl.echo2.EchoRequest(name = req.name)) | ||
return EchoResponse(message = res.message) | ||
} | ||
@Verb | ||
fun call(context: Context, req: EchoRequest): EchoResponse { | ||
val res = context.call(::echo2, ftl.echo2.EchoRequest(name = req.name)) | ||
return EchoResponse(message = res.message) | ||
} |
Oops, something went wrong.