hello world
This commit is contained in:
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
.idea
|
||||
/vendor/
|
||||
/build/
|
||||
70
docker-compose.yml
Normal file
70
docker-compose.yml
Normal file
@@ -0,0 +1,70 @@
|
||||
version: '3'
|
||||
services:
|
||||
postgres:
|
||||
command: postgres -c shared_preload_libraries=pg_stat_statements -c pg_stat_statements.track=all
|
||||
container_name: template_nk_postgres
|
||||
environment:
|
||||
- POSTGRES_DB=nakama
|
||||
- POSTGRES_PASSWORD=localdb
|
||||
expose:
|
||||
- "8080"
|
||||
- "5432"
|
||||
image: postgres:12.2-alpine
|
||||
ports:
|
||||
- "5432:5432"
|
||||
- "8080:8080"
|
||||
healthcheck:
|
||||
test: ["CMD", "pg_isready", "-U", "postgres", "-d", "nakama"]
|
||||
interval: 3s
|
||||
timeout: 3s
|
||||
retries: 5
|
||||
volumes:
|
||||
- data:/var/lib/postgresql/data
|
||||
|
||||
plugin-builder:
|
||||
image: heroiclabs/nakama-pluginbuilder:3.21.0
|
||||
container_name: nk_plugin_builder
|
||||
working_dir: /workspace
|
||||
volumes:
|
||||
- ./:/workspace
|
||||
entrypoint:
|
||||
- sh
|
||||
- -c
|
||||
- |
|
||||
mkdir -p build
|
||||
go mod tidy
|
||||
go build --trimpath --buildmode=plugin -o build/main.so ./plugins
|
||||
|
||||
nakama:
|
||||
image: heroiclabs/nakama:3.21.0
|
||||
container_name: nk_backend
|
||||
depends_on:
|
||||
- postgres
|
||||
entrypoint:
|
||||
- "/bin/sh"
|
||||
- "-ecx"
|
||||
- >
|
||||
/nakama/nakama migrate up --database.address postgres:localdb@postgres:5432/nakama?sslmode=disable &&
|
||||
exec /nakama/nakama --config /nakama/data/local.yml --database.address postgres:localdb@postgres:5432/nakama?sslmode=disable
|
||||
volumes:
|
||||
- ./local.yml:/nakama/data/local.yml
|
||||
- ./build:/nakama/data/modules
|
||||
expose:
|
||||
- "7349"
|
||||
- "7350"
|
||||
- "7351"
|
||||
healthcheck:
|
||||
test: ["CMD", "/nakama/nakama", "healthcheck"]
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
links:
|
||||
- "postgres:db"
|
||||
ports:
|
||||
- "7349:7349"
|
||||
- "7350:7350"
|
||||
- "7351:7351"
|
||||
restart: unless-stopped
|
||||
|
||||
volumes:
|
||||
data:
|
||||
7
go.mod
Normal file
7
go.mod
Normal file
@@ -0,0 +1,7 @@
|
||||
module git.aetoskia.com/lila-games/tic-tac-toe
|
||||
|
||||
go 1.21
|
||||
|
||||
require github.com/heroiclabs/nakama-common v1.31.0
|
||||
|
||||
require google.golang.org/protobuf v1.31.0 // indirect
|
||||
10
go.sum
Normal file
10
go.sum
Normal file
@@ -0,0 +1,10 @@
|
||||
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
|
||||
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
|
||||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/heroiclabs/nakama-common v1.31.0 h1:oaJbwVRUiFXA77gXF3XNrGCmR0CXf7+2vXEvaBLkP6w=
|
||||
github.com/heroiclabs/nakama-common v1.31.0/go.mod h1:Os8XeXGvHAap/p6M/8fQ3gle4eEXDGRQmoRNcPQTjXs=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
||||
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
|
||||
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
|
||||
9
local.yml
Normal file
9
local.yml
Normal file
@@ -0,0 +1,9 @@
|
||||
console:
|
||||
max_message_size_bytes: 409600
|
||||
logger:
|
||||
level: "DEBUG"
|
||||
session:
|
||||
token_expiry_sec: 7200 # 2 hours
|
||||
socket:
|
||||
max_message_size_bytes: 4096 # reserved buffer
|
||||
max_request_size_bytes: 131072
|
||||
36
plugins/main.go
Normal file
36
plugins/main.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
|
||||
"github.com/heroiclabs/nakama-common/runtime"
|
||||
)
|
||||
|
||||
func HelloWorld(
|
||||
ctx context.Context,
|
||||
logger runtime.Logger,
|
||||
db *sql.DB,
|
||||
nk runtime.NakamaModule,
|
||||
payload string,
|
||||
) (string, error) {
|
||||
logger.Info("HelloWorld RPC called — payload: %s", payload)
|
||||
return `{"message": "Hello from Go RPC!"}`, nil
|
||||
}
|
||||
|
||||
// Required module initializer
|
||||
func InitModule(
|
||||
ctx context.Context,
|
||||
logger runtime.Logger,
|
||||
db *sql.DB,
|
||||
nk runtime.NakamaModule,
|
||||
initializer runtime.Initializer,
|
||||
) error {
|
||||
if err := initializer.RegisterRpc("hello_world", HelloWorld); err != nil {
|
||||
logger.Error("Failed to register RPC: %v", err)
|
||||
return err
|
||||
}
|
||||
|
||||
logger.Info("Go module loaded successfully!")
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user