Home >Backend Development >Golang >Is golang leaf used a lot?

Is golang leaf used a lot?

(*-*)浩
(*-*)浩Original
2019-12-13 13:03:583115browse

Is golang leaf used a lot?

Leaf is an open source game server framework written in Go language (golang) that pays equal attention to development efficiency and execution efficiency. Leaf is suitable for the development of various game servers, including H5 (HTML5) game servers.

# LEAF's attention: (Recommended learning: Go )

A good experience. Leaf always provides as simple and easy-to-use interfaces as possible to improve development efficiency and stability as much as possible. Leaf always tries its best to recover from errors during operation and avoid crashes

Multi-core support. Leaf utilizes multi-core resources as much as possible through the module mechanism and leaf/go, while trying to avoid various side effects

Module mechanism.

Leaf’s module mechanism

A game server developed by Leaf consists of multiple modules (such as LeafServer). The modules have the following characteristics:

Each module runs in a separate goroutine

Communication between modules is through a set of lightweight RPC mechanisms (leaf/chanrpc)

Leaf is not recommended in game servers Design too many modules.

The game server registers modules when it starts, for example:

leaf.Run(
game.Module,
gate.Module,
login.Module,
)
Here three modules, game, gate, and login, are registered in order. Each module needs to implement an interface:

type Module interface {OnInit()OnDestroy()Run(closeSig chan bool)
}

Leaf will first execute the OnInit method of the module in the same goroutine in the order of module registration. After the execution of the OnInit method of all modules is completed, a goroutine will be started for each module and Execute the module's Run method.

Finally, when the game server is shut down (Ctrl C to close the game server), the module's OnDestroy method will be executed in the same goroutine in the reverse order of module registration.

The above is the detailed content of Is golang leaf used a lot?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Related articles

See more