gogs is a simple, fast and lightweight game server framework written in golang

  • By MetaGoGs
  • Last update: Dec 23, 2022
  • Comments: 11

gogs: Golang Game Server Framework

version codecov GitHub issues GitHub Workflow Status GitHub Release Date GitHub last commit goversion license GitHub top language

gogs is a simple, fast and lightweight game server framework written in golang. It is designed to be easy to use and easy to extend. It will generate logic code from protobuf files, and you can use it to develop your game server. It's also a good starting point for you to learn golang. It supports websocket and webrtc datachannel.


TODO

  • Support metrics
  • Support generate Unity C# SDK
  • Support generate JS SDK
  • Support Remote call
  • Support tracing
  • Support gogs generate docker file
  • Support gogs generate k8s yaml
  • Support custom game packet protocol
  • Support kubegame controller, create game pod with api
  • Add more examples
  • Add more tests
  • Add more documentation
  • Test coverage reaches 80%
  • k8s friendly, hot reload?

Getting Started

Prerequisites

Init your project

install the gogs

go install github.com/metagogs/gogs/tools/[email protected]

init project

mkdir yourgame
cd yourgame
gogs init -p yourgame

edit your proto, add the game message, then generate the code

gogs go -f data.proto

run your game server

go mod tidy
go run main.go

Generated Project

internal/
    logic/
        baseworld/
            bind_user_logic.go
    server/
        server.go
    svc/
        service_context.go
model/
    data.ep.go
    data.pb.go
config.yaml     
data.proto      
main.go

How to encode/decode the message

Packet Protocol

gogs uses 8 bytes as the protocol header

protocol header = flag + version + action index + message data length

0     byte  flag         8bit    protocol flag, awalys 0x7E 
1     byte  version      5bit    protocel version
            encodeType   3bit    protocel encode type
2     byte  packetType   2bit    packet message type 1 system 2 server
            component    6bit    message component index
3.4   byte  action       16bit   message action index
5.6.7 byte  length       24bit   message length

What is the action index

action index = packetType + component index + action index

// @gogs:Components
message Components {
    BaseWorld BaseWorld = 1; // 1 is the component index
}

message BaseWorld {
    BindUser BindUser = 1; // 1 is the action index

    BindSuccess BindSuccess = 2; // 2 is the action index
}
message BindUser {
    string uid = 1;
}


// @gogs:ServerMessage
message BindSuccess {
}

like this proto, the BindUser and BindSuccess is the message comunication between client and server

BindUser action index = packetType <<22 | component <<16 | action = 2 << 22 | 1 << 16 | 1 = 0x810001

BindSuccess action index = packetType <<22 | component <<16 | action = 2 << 22 | 1 << 16 | 2 = 0x810002

Packet encode & decode

gogs has three encode&decode types - encodeType in protocol header

  • 0 json encode&decode without protocol header
  • 1 json encode&decode with protocol header
  • 2 protobuf encode&decode with protocol header

Packet message

message with encode type 0 (json without protocol header)

message = JSON binary data

gogs retrieves the action index from the message, then gets the filed type and decodes the message, finally it calls the logic function. The json message without protocol header should add a filed named action, the value is the filed name

{
	"action": "BindUser",
	"uid": "123"
}
app.UseDefaultEncodeJSONWithHeader()

message with encode type 1 (json with protocol header)

message = 8 bytes protocol header + JSON binary data

app.UseDefaultEncodeJSON()

message with encode type 2 (protobuf with protocol header)

message = 8 bytes protocol header + protobuf binary data

app.UseDefaultEncodeProto()

Contributing

Running the gogs tests

make test

This command will run both unit and e2e tests.

Demo

License

Apache License Version 2.0

Download

gogs.zip

Comments(11)

  • 1

    Should I change the repo name?

    gogs is a famous project name.

    Should I change the repo name?

    If you think the name should be changed, please give me some advice. or you think it's ok

  • 2

    Bump github.com/pion/datachannel from 1.5.2 to 1.5.5

    Bumps github.com/pion/datachannel from 1.5.2 to 1.5.5.

    Release notes

    Sourced from github.com/pion/datachannel's releases.

    v1.5.5

    What's Changed

    Full Changelog: https://github.com/pion/datachannel/compare/v1.5.4...v1.5.5

    v1.5.4

    Full Changelog: https://github.com/pion/datachannel/compare/v1.5.3...v1.5.4

    v1.5.3

    What's Changed

    New Contributors

    Full Changelog: https://github.com/pion/datachannel/compare/v1.5.2...v1.5.3

    Commits
    • 17674f6 Update module github.com/pion/sctp to v1.8.5
    • a3f491f Update module github.com/pion/sctp to v1.8.4
    • 90f6b24 Extract SetReadDeadline from Reader to fix back compat
    • 6d03d00 Add SetReadDeadline
    • 1a83011 Update module github.com/pion/transport to v0.13.1
    • ce89fff Update CI configs to v0.7.10
    • 335abec Update CI configs to v0.7.9
    • 5c78292 Update CI configs to v0.7.8
    • f8a03b2 Update CI configs to v0.7.5
    • 212d451 Update CI configs to v0.7.3
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
  • 3

    Bump github.com/spf13/cobra from 1.6.0 to 1.6.1

    Bumps github.com/spf13/cobra from 1.6.0 to 1.6.1.

    Release notes

    Sourced from github.com/spf13/cobra's releases.

    v1.6.1

    Bug fixes 🐛

    • Fixes a panic when AddGroup isn't called before AddCommand(my-sub-command) is executed. This can happen within more complex cobra file structures that have many different inits to be executed. Now, the check for groups has been moved to ExecuteC and provides more flexibility when working with grouped commands - @​marckhouzam (and shout out to @​aawsome, @​andig and @​KINGSABRI for a deep investigation into this! 👏🏼)
    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
  • 4

    Bump github.com/pterm/pterm from 0.12.50 to 0.12.51

    Bumps github.com/pterm/pterm from 0.12.50 to 0.12.51.

    Release notes

    Sourced from github.com/pterm/pterm's releases.

    v0.12.51

    What's Changed

    Fixes 🔧

    New Contributors

    Full Changelog: https://github.com/pterm/pterm/compare/v0.12.50...v0.12.51

    Changelog

    Sourced from github.com/pterm/pterm's changelog.

    [Unreleased]

    Bug Fixes

    • Make sure the confirm printer can clean up after Ctrl+C

    Commits
    • cd598d2 Merge pull request #426 from sephiroth74/feature/option_style
    • 22f4f96 docs: autoupdate
    • 6347b39 Merge pull request #425 from adombeck/master
    • 5cf48e5 fix: Make sure the confirm printer can clean up after Ctrl+C
    • a331e6f use correct style for search text
    • 223fd94 render menu with correct style
    • See full diff in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
  • 5

    Bump github.com/gin-gonic/gin from 1.8.1 to 1.8.2

    Bumps github.com/gin-gonic/gin from 1.8.1 to 1.8.2.

    Release notes

    Sourced from github.com/gin-gonic/gin's releases.

    v1.8.2

    Changelog

    Bug fixes

    • 0c2a691 fix(engine): missing route params for CreateTestContext (#2778) (#2803)
    • e305e21 fix(route): redirectSlash bug (#3227)

    Others

    • 6a2a260 Fix the GO-2022-1144 vulnerability (#3432)
    Changelog

    Sourced from github.com/gin-gonic/gin's changelog.

    Gin v1.8.2

    Bugs

    • fix(route): redirectSlash bug (#3227)
    • fix(engine): missing route params for CreateTestContext (#2778) (#2803)

    Security

    • Fix the GO-2022-1144 vulnerability (#3432)
    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
  • 6

    Bump github.com/pion/webrtc/v3 from 3.1.49 to 3.1.50

    Bumps github.com/pion/webrtc/v3 from 3.1.49 to 3.1.50.

    Release notes

    Sourced from github.com/pion/webrtc/v3's releases.

    v3.1.50

    What's Changed

    New Contributors

    Full Changelog: https://github.com/pion/webrtc/compare/v3.1.49...v3.1.50

    Commits
    • 1c20cd4 Update datachannel and sctp to latest
    • 720d9b0 Update module github.com/pion/transport to v0.14.1
    • 6a5997b Update module golang.org/x/net to v0.3.0
    • See full diff in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
  • 7

    Bump github.com/bytedance/sonic from 1.5.0 to 1.6.0

    Bumps github.com/bytedance/sonic from 1.5.0 to 1.6.0.

    Release notes

    Sourced from github.com/bytedance/sonic's releases.

    v1.6.0

    Feature

    • #305 only use SSE instead of SSE4 to be compatible with old x86 CPU
    • #306 add dummy interface of pretouch() under not-amd64 arch
    • #325 (decoder) support skipping mismatched-typed value while binding
    • #329 support decode json-encoded (with escaping characters) base64 string

    Bugfix

    • #314 (ast) iterator panic while traversing the empty object
    • #320 (decoder) clear corrupt memory when decoding failed

    Optimization

    • #302 reduce memory pool size of JIT's stack (1~3+MB per P)
    • #324 reduce type assertions in ast

    Full Changelog: https://github.com/bytedance/sonic/compare/v1.5.0...v1.6.0

    v1.6.0-rc

    Feature

    • #325 (decoder) support skipping mismatched-typed value while binding
    • #320 (decoder) clear corrupt memory when decoding failed
    • #306 add dummy interface of pretouch() under not-amd64 arch

    Bugfix

    • #305 only use SSE instead of SSE4 to be compatible with old x86 CPU
    • #314 (ast) iterator panic while traversing the empty object

    Optimization

    • #302 reduce memory pool size of JIT's stack (1~3+MB per P)
    • #324 (ast) reduce type assertion

    Full Changelog: https://github.com/bytedance/sonic/compare/v1.5.0...v1.6.0-rc

    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
  • 8

    Bump github.com/emicklei/proto from 1.11.0 to 1.11.1

    Bumps github.com/emicklei/proto from 1.11.0 to 1.11.1.

    Changelog

    Sourced from github.com/emicklei/proto's changelog.

    v1.11.1 (2022-12-01)

    • added Doc for MapField so it implements Documented
    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
  • 9

    Bump go.uber.org/zap from 1.23.0 to 1.24.0

    Bumps go.uber.org/zap from 1.23.0 to 1.24.0.

    Release notes

    Sourced from go.uber.org/zap's releases.

    v1.24.0

    Enhancements:

    • #1148[]: Add Level to both Logger and SugaredLogger that reports the current minimum enabled log level.
    • #1185[]: SugaredLogger turns errors to zap.Error automatically.

    Thanks to @​Abirdcfly, @​craigpastro, @​nnnkkk7, and @​sashamelentyev for their contributions to this release.

    #1148: uber-go/zap#1148 #1185: uber-go/zap#1185

    Changelog

    Sourced from go.uber.org/zap's changelog.

    1.24.0 (30 Nov 2022)

    Enhancements:

    • #1148[]: Add Level to both Logger and SugaredLogger that reports the current minimum enabled log level.
    • #1185[]: SugaredLogger turns errors to zap.Error automatically.

    Thanks to @​Abirdcfly, @​craigpastro, @​nnnkkk7, and @​sashamelentyev for their contributions to this release.

    #1148: https://github.coml/uber-go/zap/pull/1148 #1185: https://github.coml/uber-go/zap/pull/1185

    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
  • 10

    Bump github.com/pion/webrtc/v3 from 3.1.48 to 3.1.49

    Bumps github.com/pion/webrtc/v3 from 3.1.48 to 3.1.49.

    Release notes

    Sourced from github.com/pion/webrtc/v3's releases.

    v3.1.49

    Changelog

    • c75da54 Add EnableLoopbackCandidate flag
    • 5faad1e Update module github.com/pion/ice/v2 to v2.2.12
    • 2ebf9c6 Fix docs typo
    • 1365b0a Update CI configs to v0.8.1
    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
  • 11

    Bump github.com/tidwall/gjson from 1.14.3 to 1.14.4

    Bumps github.com/tidwall/gjson from 1.14.3 to 1.14.4.

    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)