Skip to content

Commit

Permalink
Use main() in service and virtual object
Browse files Browse the repository at this point in the history
  • Loading branch information
jackkleeman committed Aug 15, 2024
1 parent a227806 commit cdf3fba
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package develop
package main

import (
"context"
"fmt"
"log"

restate "github.com/restatedev/sdk-go"
server "github.com/restatedev/sdk-go/server"
Expand All @@ -14,8 +15,10 @@ func (MyService) MyHandler(ctx restate.Context, greeting string) (string, error)
return fmt.Sprintf("%s!", greeting), nil
}

func serveMyService() {
server.NewRestate().
func main() {
if err := server.NewRestate().
Bind(restate.Reflect(MyService{})).
Start(context.Background(), "0.0.0.0:9080")
Start(context.Background(), "0.0.0.0:9080"); err != nil {
log.Fatal(err)
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package develop
package main

import (
"context"
"fmt"
"log"

restate "github.com/restatedev/sdk-go"
server "github.com/restatedev/sdk-go/server"
Expand All @@ -18,8 +19,10 @@ func (MyVirtualObject) MyConcurrentHandler(ctx restate.ObjectSharedContext, gree
return fmt.Sprintf("%s %s!", greeting, ctx.Key()), nil
}

func serveMyVirtualObject() error {
return server.NewRestate().
func main() {
if err := server.NewRestate().
Bind(restate.Reflect(MyVirtualObject{})).
Start(context.Background(), "0.0.0.0:9080")
Start(context.Background(), "0.0.0.0:9080"); err != nil {
log.Fatal(err)
}
}
3 changes: 3 additions & 0 deletions code_snippets/go/develop/servinglambda.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import (
server "github.com/restatedev/sdk-go/server"
)

type MyService struct{}
type MyVirtualObject struct{}

func serveLambda() {
// <start_lambda>
handler, err := server.NewRestate().
Expand Down
4 changes: 2 additions & 2 deletions docs/develop/go/overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Handlers can either be part of a [Service](/concepts/services#services-1), or a
[Services](/concepts/services#services-1) and their handlers are defined as follows:

```go
CODE_LOAD::go/develop/myservice.go
CODE_LOAD::go/develop/myservice/main.go
```

- Define a Service by implementing exported methods on any struct.
Expand Down Expand Up @@ -51,7 +51,7 @@ CODE_LOAD::go/develop/myservice.go
[Virtual Objects](/concepts/services#virtual-objects) and their handlers are defined similarly to services, with the following differences:

```go
CODE_LOAD::go/develop/myvirtualobject.go
CODE_LOAD::go/develop/myvirtualobject/main.go
```

- We pass the struct to `restate.Object` instead of `restate.Service`.
Expand Down

0 comments on commit cdf3fba

Please sign in to comment.