Skip to content

Commit df5562b

Browse files
committed
gogame based on flowstate versoin with data in state ctx
Based on makasim/flowstate#97
1 parent 8e6f245 commit df5562b

File tree

20 files changed

+690
-376
lines changed

20 files changed

+690
-376
lines changed

deployment.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ spec:
4848
spec:
4949
containers:
5050
- name: flowstatesrv
51-
image: docker.io/makasim/flowstate:e662c53f
51+
image: docker.io/makasim/flowstate:372320ea
5252
ports:
5353
- containerPort: 9282
5454
env:

go.mod

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,20 @@ go 1.24.0
55
toolchain go1.24.3
66

77
require (
8-
connectrpc.com/connect v1.18.1
9-
github.com/makasim/flowstate v0.0.0-20250726121746-e662c53f5288
8+
connectrpc.com/connect v1.19.0
9+
github.com/VictoriaMetrics/easyproto v0.1.4
10+
github.com/makasim/flowstate v0.0.0-20250928165947-4916d95f4b01
11+
github.com/oklog/ulid/v2 v2.1.1
1012
github.com/otrego/clamshell v0.0.0-20220814024334-043dd78cf746
1113
github.com/rs/cors v1.11.1
12-
golang.org/x/net v0.38.0
13-
google.golang.org/protobuf v1.36.6
14+
golang.org/x/net v0.44.0
15+
google.golang.org/protobuf v1.36.9
1416
)
1517

1618
require (
17-
github.com/VictoriaMetrics/easyproto v0.1.4 // indirect
19+
github.com/cespare/xxhash/v2 v2.3.0 // indirect
1820
github.com/google/go-cmp v0.7.0 // indirect
19-
github.com/oklog/ulid/v2 v2.1.1 // indirect
20-
golang.org/x/text v0.23.0 // indirect
21+
golang.org/x/text v0.29.0 // indirect
2122
golang.org/x/time v0.6.0 // indirect
2223
)
2324

go.sum

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
connectrpc.com/connect v1.18.1 h1:PAg7CjSAGvscaf6YZKUefjoih5Z/qYkyaTrBW8xvYPw=
22
connectrpc.com/connect v1.18.1/go.mod h1:0292hj1rnx8oFrStN7cB4jjVBeqs+Yx5yDIC2prWDO8=
3+
connectrpc.com/connect v1.19.0 h1:LuqUbq01PqbtL0o7vn0WMRXzR2nNsiINe5zfcJ24pJM=
4+
connectrpc.com/connect v1.19.0/go.mod h1:tN20fjdGlewnSFeZxLKb0xwIZ6ozc3OQs2hTXy4du9w=
35
github.com/VictoriaMetrics/easyproto v0.1.4 h1:r8cNvo8o6sR4QShBXQd1bKw/VVLSQma/V2KhTBPf+Sc=
46
github.com/VictoriaMetrics/easyproto v0.1.4/go.mod h1:QlGlzaJnDfFd8Lk6Ci/fuLxfTo3/GThPs2KH23mv710=
7+
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
8+
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
59
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
610
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
711
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
812
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
913
github.com/gorhill/cronexpr v0.0.0-20180427100037-88b0669f7d75 h1:f0n1xnMSmBLzVfsMMvriDyA75NB/oBgILX2GcHXIQzY=
1014
github.com/gorhill/cronexpr v0.0.0-20180427100037-88b0669f7d75/go.mod h1:g2644b03hfBX9Ov0ZBDgXXens4rxSxmqFBbhvKv2yVA=
11-
github.com/makasim/flowstate v0.0.0-20250726121746-e662c53f5288 h1:ajU8iOGqcXWIL4FHaU9bIVZYiBHNYb3ZlObu+ewT4SQ=
12-
github.com/makasim/flowstate v0.0.0-20250726121746-e662c53f5288/go.mod h1:576Odv1ZCb4I12pDq72WbZrwLegxzh5xpc1Fe0KDdIw=
15+
github.com/makasim/flowstate v0.0.0-20250928112803-eb5364b83eb4 h1:03a5XK93tbmw6aPOQWLllclY/pMbLuzeoke7OZAXxIM=
16+
github.com/makasim/flowstate v0.0.0-20250928112803-eb5364b83eb4/go.mod h1:Q2DpFG+Wx13WP4Vj5e7BilfRKa0cWrm21cYNzWg1zsw=
17+
github.com/makasim/flowstate v0.0.0-20250928165947-4916d95f4b01 h1:OhhDaqVVlixyCbhhPSTvU4mYAHH4n6Mu5kSg0xYpmDw=
18+
github.com/makasim/flowstate v0.0.0-20250928165947-4916d95f4b01/go.mod h1:Q2DpFG+Wx13WP4Vj5e7BilfRKa0cWrm21cYNzWg1zsw=
1319
github.com/oklog/ulid/v2 v2.1.1 h1:suPZ4ARWLOJLegGFiZZ1dFAkqzhMjL3J1TzI+5wHz8s=
1420
github.com/oklog/ulid/v2 v2.1.1/go.mod h1:rcEKHmBBKfef9DhnvX7y1HZBYxjXb0cP5ExxNsTT1QQ=
1521
github.com/otrego/clamshell v0.0.0-20220814024334-043dd78cf746 h1:lRPeFeuZAdclG9NZudMoF5T+sImSK/YqGI7spKR7q/U=
@@ -27,11 +33,16 @@ go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
2733
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
2834
golang.org/x/net v0.38.0 h1:vRMAPTMaeGqVhG5QyLJHqNDwecKTomGeqbnfZyKlBI8=
2935
golang.org/x/net v0.38.0/go.mod h1:ivrbrMbzFq5J41QOQh0siUuly180yBYtLp+CKbEaFx8=
36+
golang.org/x/net v0.44.0 h1:evd8IRDyfNBMBTTY5XRF1vaZlD+EmWx6x8PkhR04H/I=
37+
golang.org/x/net v0.44.0/go.mod h1:ECOoLqd5U3Lhyeyo/QDCEVQ4sNgYsqvCZ722XogGieY=
3038
golang.org/x/text v0.23.0 h1:D71I7dUrlY+VX0gQShAThNGHFxZ13dGLBHQLVl1mJlY=
3139
golang.org/x/text v0.23.0/go.mod h1:/BLNzu4aZCJ1+kcD0DNRotWKage4q2rGVAg4o22unh4=
40+
golang.org/x/text v0.29.0/go.mod h1:7MhJOA9CD2qZyOKYazxdYMF85OwPdEr9jTtBpO7ydH4=
3241
golang.org/x/time v0.6.0 h1:eTDhh4ZXt5Qf0augr54TN6suAUudPcawVZeIAPU7D4U=
3342
golang.org/x/time v0.6.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
3443
google.golang.org/protobuf v1.36.6 h1:z1NpPI8ku2WgiWnf+t9wTPsn6eP1L7ksHUlkfLvd9xY=
3544
google.golang.org/protobuf v1.36.6/go.mod h1:jduwjTPXsFjZGTmRluh+L6NjiWu7pchiJ2/5YcXBHnY=
45+
google.golang.org/protobuf v1.36.9 h1:w2gp2mA27hUeUzj9Ex9FBjsBm40zfaDtEWow293U7Iw=
46+
google.golang.org/protobuf v1.36.9/go.mod h1:fuxRtAxBytpl4zzqUh6/eyUujkJdNiuEkXntxiD/uRU=
3647
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
3748
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

internal/api/convertor/data.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,31 +12,31 @@ func GameToData(g *v1.Game, d *flowstate.Data) error {
1212
return err
1313
}
1414

15-
d.ID = flowstate.DataID(g.Id)
16-
d.B = b
15+
d.Blob = b
1716
return nil
1817
}
1918

2019
func DataToGame(d *flowstate.Data) (*v1.Game, error) {
2120
g := &v1.Game{}
22-
if err := protojson.Unmarshal(d.B, g); err != nil {
21+
if err := protojson.Unmarshal(d.Blob, g); err != nil {
2322
return nil, err
2423
}
2524

2625
return g, nil
2726
}
2827

2928
func FindGame(e flowstate.Engine, gID string, gRev int32) (*v1.Game, *flowstate.StateCtx, *flowstate.Data, error) {
30-
d := &flowstate.Data{}
3129
stateCtx := &flowstate.StateCtx{}
3230

3331
if err := e.Do(
3432
flowstate.GetStateByID(stateCtx, flowstate.StateID(gID), int64(gRev)),
35-
flowstate.GetData(stateCtx, d, `game`),
33+
flowstate.GetData(stateCtx, `game`),
3634
); err != nil {
3735
return nil, nil, nil, err
3836
}
3937

38+
d := stateCtx.MustData(`game`)
39+
4040
g, err := DataToGame(d)
4141
if err != nil {
4242
return nil, nil, nil, err

internal/api/convertor/undo.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package convertor
22

33
import (
4-
"fmt"
5-
64
"github.com/makasim/flowstate"
75
v1 "github.com/makasim/gogame/protogen/gogame/v1"
86
"google.golang.org/protobuf/encoding/protojson"
@@ -14,14 +12,14 @@ func UndoToData(u *v1.Undo, d *flowstate.Data) error {
1412
return err
1513
}
1614

17-
d.ID = flowstate.DataID(fmt.Sprintf("%s-%d", u.GameId, u.GameRev))
18-
d.B = b
15+
//d.ID = flowstate.DataID(fmt.Sprintf("%s-%d", u.GameId, u.GameRev))
16+
d.Blob = b
1917
return nil
2018
}
2119

2220
func DataToUndo(d *flowstate.Data) (*v1.Undo, error) {
2321
u := &v1.Undo{}
24-
if err := protojson.Unmarshal(d.B, u); err != nil {
22+
if err := protojson.Unmarshal(d.Blob, u); err != nil {
2523
return nil, err
2624
}
2725

internal/api/corsmiddleware/cors.go

Lines changed: 0 additions & 37 deletions
This file was deleted.

internal/api/gameservicev1/service.go

Lines changed: 6 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,6 @@ import (
1010

1111
var _ gogamev1connect.GameServiceHandler = (*Service)(nil)
1212

13-
type createGameHandler interface {
14-
CreateGame(_ context.Context, req *connect.Request[v1.CreateGameRequest]) (*connect.Response[v1.CreateGameResponse], error)
15-
}
16-
17-
type joinGameHandler interface {
18-
JoinGame(_ context.Context, req *connect.Request[v1.JoinGameRequest]) (*connect.Response[v1.JoinGameResponse], error)
19-
}
20-
2113
type streamVacantGamesHandler interface {
2214
StreamVacantGames(ctx context.Context, req *connect.Request[v1.StreamVacantGamesRequest], stream *connect.ServerStream[v1.StreamVacantGamesResponse]) error
2315
}
@@ -26,61 +18,27 @@ type streamGameEventsHandler interface {
2618
StreamGameEvents(context.Context, *connect.Request[v1.StreamGameEventsRequest], *connect.ServerStream[v1.StreamGameEventsResponse]) error
2719
}
2820

29-
type makeMoveHandler interface {
30-
MakeMove(_ context.Context, req *connect.Request[v1.MakeMoveRequest]) (*connect.Response[v1.MakeMoveResponse], error)
31-
}
32-
33-
type resignHandler interface {
34-
Resign(context.Context, *connect.Request[v1.ResignRequest]) (*connect.Response[v1.ResignResponse], error)
35-
}
36-
37-
type passHandler interface {
38-
Pass(context.Context, *connect.Request[v1.PassRequest]) (*connect.Response[v1.PassResponse], error)
39-
}
40-
41-
type undoHandler interface {
42-
Undo(_ context.Context, req *connect.Request[v1.UndoRequest]) (*connect.Response[v1.UndoResponse], error)
43-
}
44-
4521
type Service struct {
46-
cgh createGameHandler
47-
jgh joinGameHandler
4822
svgh streamVacantGamesHandler
4923
sgeh streamGameEventsHandler
50-
mmh makeMoveHandler
51-
rh resignHandler
52-
ph passHandler
53-
uh undoHandler
5424
}
5525

5626
func New(
57-
cgh createGameHandler,
58-
jgh joinGameHandler,
5927
svgh streamVacantGamesHandler,
6028
sgeh streamGameEventsHandler,
61-
mmh makeMoveHandler,
62-
rh resignHandler,
63-
ph passHandler,
64-
uh undoHandler,
6529
) *Service {
6630
return &Service{
67-
cgh: cgh,
68-
jgh: jgh,
6931
svgh: svgh,
7032
sgeh: sgeh,
71-
mmh: mmh,
72-
rh: rh,
73-
ph: ph,
74-
uh: uh,
7533
}
7634
}
7735

7836
func (s *Service) CreateGame(ctx context.Context, req *connect.Request[v1.CreateGameRequest]) (*connect.Response[v1.CreateGameResponse], error) {
79-
return s.cgh.CreateGame(ctx, req)
37+
panic("BUG: CreateGame must not be called")
8038
}
8139

8240
func (s *Service) JoinGame(ctx context.Context, req *connect.Request[v1.JoinGameRequest]) (*connect.Response[v1.JoinGameResponse], error) {
83-
return s.jgh.JoinGame(ctx, req)
41+
panic("BUG: JoinGame must not be called")
8442
}
8543

8644
func (s *Service) StreamVacantGames(ctx context.Context, req *connect.Request[v1.StreamVacantGamesRequest], stream *connect.ServerStream[v1.StreamVacantGamesResponse]) error {
@@ -92,17 +50,17 @@ func (s *Service) StreamGameEvents(ctx context.Context, req *connect.Request[v1.
9250
}
9351

9452
func (s *Service) MakeMove(ctx context.Context, req *connect.Request[v1.MakeMoveRequest]) (*connect.Response[v1.MakeMoveResponse], error) {
95-
return s.mmh.MakeMove(ctx, req)
53+
panic("BUG: MakeMove must not be called")
9654
}
9755

9856
func (s *Service) Pass(ctx context.Context, req *connect.Request[v1.PassRequest]) (*connect.Response[v1.PassResponse], error) {
99-
return s.ph.Pass(ctx, req)
57+
panic("BUG: Pass must not be called")
10058
}
10159

10260
func (s *Service) Resign(ctx context.Context, req *connect.Request[v1.ResignRequest]) (*connect.Response[v1.ResignResponse], error) {
103-
return s.rh.Resign(ctx, req)
61+
panic("BUG: Resign must not be called")
10462
}
10563

10664
func (s *Service) Undo(ctx context.Context, req *connect.Request[v1.UndoRequest]) (*connect.Response[v1.UndoResponse], error) {
107-
return s.uh.Undo(ctx, req)
65+
panic("BUG: Undo must not be called")
10866
}

internal/api/gameservicev1/streamgameeventshandler/handler.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,19 @@ func (h *Handler) StreamGameEvents(ctx context.Context, req *connect.Request[v1.
4343
gID := state.Annotations[`game.id`]
4444
gRev, _ := strconv.ParseInt(state.Annotations[`game.rev`], 10, 0)
4545

46-
d := &flowstate.Data{}
4746
stateCtx := &flowstate.StateCtx{}
48-
4947
undoStateCtx := state.CopyToCtx(&flowstate.StateCtx{})
50-
undoD := &flowstate.Data{}
5148
if err := h.e.Do(
5249
flowstate.GetStateByID(stateCtx, flowstate.StateID(gID), gRev),
53-
flowstate.GetData(stateCtx, d, `game`),
54-
flowstate.GetData(undoStateCtx, undoD, `undo`),
50+
flowstate.GetData(stateCtx, `game`),
51+
flowstate.GetData(undoStateCtx, `undo`),
5552
); err != nil {
5653
continue
5754
}
5855

56+
d := stateCtx.MustData(`game`)
57+
undoD := undoStateCtx.MustData(`undo`)
58+
5959
u, err := convertor.DataToUndo(undoD)
6060
if err != nil {
6161
continue

0 commit comments

Comments
 (0)