MCPcopy
hub / github.com/lonng/nano

github.com/lonng/nano @v0.5.1 sqlite

repository ↗ · DeepWiki ↗ · release v0.5.1 ↗
1,124 symbols 2,758 edges 100 files 268 documented · 24%
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.

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

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

Extension points exported contracts — how you extend this code

NetworkEntity (Interface)
NetworkEntity represent low-level network instance [3 implementers]
session/session.go
Marshaler (Interface)
Marshaler represents a marshal interface [2 implementers]
serialize/serializer.go
Component (Interface)
Component is the interface that represent a component. [1 implementers]
component/component.go
SessionFilter (FuncType)
SessionFilter represents a filter which was used to filter session when Multicast, the session will receive the message
group.go
TimerFunc (FuncType)
TimerFunc represents a function which will be called periodically in main logic gorontine.
scheduler/timer.go
LocalScheduler (Interface)
LocalScheduler schedules task to a customized goroutine
scheduler/scheduler.go
Option (FuncType)
Option used to customize handler
component/options.go
Connection (Interface)
(no doc) [2 implementers]
service/connection.go

Core symbols most depended-on inside this repo

Println
called by 105
internal/log/logger.go
ID
called by 23
scheduler/timer.go
String
called by 23
cluster/agent.go
New
called by 22
session/session.go
UID
called by 22
session/session.go
Fatalf
called by 21
internal/log/logger.go
Set
called by 16
session/session.go
Fatal
called by 12
internal/log/logger.go

Shape

Function 560
Method 430
Struct 104
Interface 17
FuncType 11
TypeAlias 2

Languages

Go65%
TypeScript35%

Modules by API surface

examples/demo/tadpole/static/js/lib/vue.min.js195 symbols
cluster/clusterpb/cluster.pb.go150 symbols
cluster/clusterpb/cluster_grpc.pb.go71 symbols
session/session.go42 symbols
examples/demo/tadpole/static/js/lib/jquery-1.4.2.min.js32 symbols
examples/demo/tadpole/static/js/lib/starx-wsclient.js23 symbols
examples/demo/chat/web/starx-wsclient.js23 symbols
examples/customerroute/onemaster/web/starx-wsclient.js23 symbols
examples/cluster/master/web/starx-wsclient.js23 symbols
options.go22 symbols
cluster/node.go21 symbols
benchmark/io/connector.go20 symbols

Used by 3 indexed graphs manifest dependencies, hub-wide

Dependencies from manifests, versioned

github.com/cpuguy83/go-md2man/v2v2.0.0 · 1×
github.com/pingcap/checkv0.0.0-2020021206183 · 1×
github.com/pingcap/errorsv0.11.4 · 1×
github.com/pingcap/logv0.0.0-2021062512590 · 1×
github.com/urfave/cliv1.22.5 · 1×
go.uber.org/atomicv1.8.0 · 1×
go.uber.org/multierrv1.7.0 · 1×
go.uber.org/zapv1.18.1 · 1×

For agents

$ claude mcp add nano \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact