Skip to content

Commit 89fb45b

Browse files
author
Adriano Santos
committed
doc: add some docs
1 parent c5e2026 commit 89fb45b

File tree

5 files changed

+77
-4
lines changed

5 files changed

+77
-4
lines changed

README.md

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,30 @@
1-
# spawn-go-sdk
2-
Go SDK for the Eigr Actor Mesh
1+
# Spawn Go SDK
2+
3+
# [Spawn](https://github.com/eigr/spawn)
4+
5+
**Spawn Actor Mesh Runtime for Go**
6+
7+
## **Installation**
8+
9+
### Install Spawn CLI
10+
11+
```SH
12+
curl -sSL https://github.com/eigr/spawn/releases/download/v1.4.3/install.sh | sh
13+
```
14+
15+
# **Getting Started**
16+
17+
Install go package.
18+
19+
```go
20+
```
21+
22+
### Create a new project with
23+
24+
```SH
25+
spawn new go hello_world
26+
```
27+
28+
## **Examples**
29+
30+
You can check [examples folder](./examples) to see some examples

documentation/actors.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Actors
2+
3+
his is an example of what kind of Actors you can create with Spawn
4+
5+
## Named Actor
6+
7+
In this example we are creating an actor in a Named way, that is, it is a known actor at compile time. Or a 'global' actor with only one name.
8+
9+
```go
10+
actorConfig := spawn.ActorConfig{
11+
Name: "UserActor", // Nome do ator
12+
StateType: &actors.UserState{}, // State type
13+
Kind: spawn.Named, // Actor Type (Named)
14+
Stateful: true, // Stateful actor
15+
SnapshotTimeout: 60, // Snapshot timeout
16+
DeactivatedTimeout: 120, // Deactivation timeout
17+
}
18+
```
19+
20+
```go
21+
// Creates an actor with the given configuration
22+
actor := system.BuildActor(actorConfig)
23+
24+
// Define uma ação simples para o ator
25+
actor.AddAction("ChangeUserName", func(ctx spawn.ActorContext, payload proto.Message) (spawn.Value, error) {
26+
// Convert payload to expected type
27+
input, ok := payload.(*actors.ChangeUserNamePayload)
28+
if !ok {
29+
return spawn.Value{}, fmt.Errorf("invalid payload type")
30+
}
31+
32+
// Updates the status and prepares the response
33+
state := &actors.UserState{Name: input.NewName}
34+
response := &actors.ChangeUserNameResponse{Status: actors.ChangeUserNameResponse_OK}
35+
36+
// Returns status and response
37+
return spawn.Of(state, response), nil
38+
})
39+
```

examples/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ require (
99
google.golang.org/protobuf v1.35.2
1010
)
1111

12-
replace github.com/eigr/spawn-go-sdk/spawn => ../spawn
12+
//replace github.com/eigr/spawn-go-sdk/spawn => ../spawn

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ require (
88
github.com/eigr/spawn-go-sdk/spawn v0.1.0
99
)
1010

11-
replace github.com/eigr/spawn-go-sdk/spawn => ./spawn
11+
//replace github.com/eigr/spawn-go-sdk/spawn => ./spawn

go.work.sum

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
2+
golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg=
3+
golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
4+
golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
5+
google.golang.org/genproto/googleapis/rpc v0.0.0-20241206012308-a4fef0638583/go.mod h1:5uTbfoYQed2U9p3KIj2/Zzm02PYhndfdmML0qC3q3FU=
6+
google.golang.org/grpc v1.67.1/go.mod h1:1gLDyUQU7CTLJI90u3nXZ9ekeghjeM7pTDZlqFNg2AA=

0 commit comments

Comments
 (0)