返回排行榜

lonng/nano

Go

Lightweight, facility, high performance golang based game server framework

golanggameserverprotobufjsontcp-serverwebsocket-servernetworkinglightweightmicrodistributed-systems
Star 增长趋势
Star
3.2k
Forks
464
周增长
Issues
29
1k2k3k
2017年8月2020年7月2023年7月2026年7月
制品库Go Modulesgo get github.com/lonng/nano
README

Nano Build Status GoDoc Go Report Card MIT licensed

Nano is an easy to use, fast, lightweight game server networking library for Go. It provides a core network architecture and a series of tools and libraries that can help developers eliminate boring duplicate work for common underlying logic. The goal of nano is to improve development efficiency by eliminating the need to spend time on repetitious network related programming.

Nano was designed for server-side applications like real-time games, social games, mobile games, etc of all sizes.

Join to Discord: Nano Community

How to build a system with Nano

What does a Nano application look like?

The simplest "nano" application as shown in the following figure, you can make powerful applications by combining different components.

Application

In fact, the nano application is a collection of  Component , and a component is a bundle of  Handler, once you register a component to nano, nano will register all methods that can be converted to Handler to nano service container. Service was accessed by Component.Handler, and the handler will be called while client request. The handler will receive two parameters while handling a message:

  • *session.Session: corresponding a client that apply this request or notify.
  • *protocol.FooBar: the payload of the request.

While you had processed your logic, you can response or push message to the client by session.Response(payload) and session.Push('eventName', payload), or returns error when some unexpected data received.

How to build distributed system with Nano

Nano contains built-in distributed system solution, and make you creating a distributed game server easily.

See: The distributed chat demo

The Nano will remain simple, but you can perform any operations in the component and get the desired goals. You can startup a group of Nano application as agent to dispatch message to backend servers.

How to execute the asynchronous task

func (manager *PlayerManager) Login(s *session.Session, msg *ReqPlayerLogin) error {
    var onDBResult = func(player *Player) {
        manager.players = append(manager.players, player)
        s.Push("PlayerSystem.LoginSuccess", &ResPlayerLogin)
    }
    
    // run slow task in new gorontine
    go func() {
        player, err := db.QueryPlayer(msg.PlayerId) // ignore error in demo
        // handle result in main logical gorontine
        nano.Invoke(func(){ onDBResult(player) })
    }
    return nil
}

Documents

Resources

Community

  • QQGroup: 289680347 Q群已满员(加微信 gsw_945 邀请进微信群, 需备注 nano加群)
  • Reddit: nanolabs

Successful cases

Go version

> go1.8

Installation

go get github.com/lonng/nano

# dependencies
go get -u github.com/pingcap/check
go get -u github.com/pingcap/errors
go get -u github.com/urfave/cli

go get -u google.golang.org/protobuf/proto
go get -u github.com/gorilla/websocket
go get -u google.golang.org/grpc

Protocol Buffers

# protoc
# download form: https://github.com/protocolbuffers/protobuf/releases
# protoc-gen-go
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
# delve
go install github.com/go-delve/delve/cmd/dlv@latest

Test

go test -v ./...

Benchmark

# Case:   PingPong
# OS:     Windows 10
# Device: i5-6500 3.2GHz 4 Core/1000-Concurrent   => IOPS 11W(Average)
# Other:  ...

cd ./benchmark/io
go test -v -tags "benchmark"

License

MIT License

相关仓库
practical-tutorials/project-based-learning

Curated list of project-based tutorials

PythonPyPIMIT Licensetutorialproject
274.4k35.4k
avelino/awesome-go

A curated list of awesome Go frameworks, libraries and software

GoGo ModulesMIT Licensegolanggolang-library
awesome-go.com
178.7k13.4k
ollama/ollama

Get up and running with Kimi-K2.6, GLM-5.2, MiniMax, DeepSeek, gpt-oss, Qwen, Gemma and other models.

GoGo ModulesMIT Licensellamallm
ollama.com
176.5k17k
golang/go

The Go programming language

GoGo ModulesBSD 3-Clause "New" or "Revised" Licenseprogramming-languagelanguage
go.dev
135.3k19.3k
caddyserver/caddy

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS

GoGo ModulesApache License 2.0goweb-server
caddyserver.com
74.2k4.8k
unionlabs/union

The trust-minimized, zero-knowledge bridging protocol, designed for censorship resistance, extremely high security, and usage in decentralized finance.

Rustcrates.ioApache License 2.0blockchaincosmos
union.build
73.9k3.9k
moby/moby

The Moby Project - a collaborative project for the container ecosystem to assemble container-based systems

GoGo ModulesApache License 2.0dockercontainers
mobyproject.org
71.9k19k
nektos/act

Run your GitHub Actions locally 🚀

GoGo ModulesMIT Licensegithub-actionsgolang
nektosact.com
71.1k2k
traefik/traefik

The Cloud Native Application Proxy

GoGo ModulesMIT Licensemicroservicedocker
traefik.io
64.1k6.1k
santifer/career-ops

Open-source AI job search: scan job portals, score listings A-F, tailor your CV, track applications — runs locally in your AI coding CLI (Claude Code, Gemini, Codex, OpenCode…)

JavaScriptnpmMIT Licenseai-agentanthropic
career-ops.org
60.8k12k
pocketbase/pocketbase

Open Source realtime backend in 1 file

GoGo ModulesMIT Licenseauthenticationbackend
pocketbase.io
60.1k3.6k
rclone/rclone

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

GoGo ModulesMIT Licensegolanggo
rclone.org
58.5k5.2k