-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexample_plugin.go
38 lines (31 loc) · 982 Bytes
/
example_plugin.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package main
import (
"context"
"database/sql"
"fmt"
"github.com/heroiclabs/nakama/runtime"
"github.com/mastern2k3/poseidon/liveparams"
"github.com/mastern2k3/poseidon/rpc"
)
var (
myLiveInt *int
myLiveString *string
testRoutes = []rpc.RPCRoute{
&rpc.StringRoute{"test_live_int", testLiveInt},
}
)
func InitModule(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, initializer runtime.Initializer) error {
if err := liveparams.RegisterLiveParameters(ctx, nk, initializer, func(reg liveparams.Registrar) {
myLiveInt = reg.LiveInt("liveint", 12)
myLiveString = reg.LiveString("livestring", "hello")
}); err != nil {
return err
}
if err := rpc.RegisterRoutes(initializer, testRoutes); err != nil {
return err
}
return nil
}
func testLiveInt(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, payload string) (string, error) {
return fmt.Sprintf("%d %s", *myLiveInt, *myLiveString), nil
}