leaf开源服务器第一节-分析项目结构
2017-11-07 16:21
246 查看
leaf开源游戏服务器源码
首先,leaf开源服务器-大多数网上文章介绍都是关于游戏服务器的;其实总体框架来说,做H5聊天服务器也可以的;同时leaf总体设计来说,个人认为此框架不仅仅适合游戏。
项目入口
![](http://www.golang.ltd/data/attachment/forum/201711/07/080859hsl8z68ysyymyoey.png)
main.go
package main
import (
"server/conf"
"server/game"
"server/gate"
"server/login"
"github.com/name5566/leaf"
lconf "github.com/name5566/leaf/conf"
)
func main() {
// 加载配置
lconf.LogLevel = conf.Server.LogLevel
lconf.LogPath = conf.Server.LogPath
lconf.LogFlag = conf.LogFlag
lconf.ConsolePort = conf.Server.ConsolePort
lconf.ProfilePath = conf.Server.ProfilePath
// 运行
leaf.Run(
game.Module,
gate.Module,
login.Module,
)
}
复制代码
从主函数分析
// 加载配置
lconf.LogLevel = conf.Server.LogLevel
lconf.LogPath = conf.Server.LogPath
lconf.LogFlag = conf.LogFlag
lconf.ConsolePort = conf.Server.ConsolePort
lconf.ProfilePath = conf.Server.ProfilePath
复制代码
加载配置文件,配置文件在哪里?
![](http://www.golang.ltd/data/attachment/forum/201711/07/081047cxvvpy349vyx3xh4.png)
json.go 源码
package conf
import (
"encoding/json"
"io/ioutil"
"github.com/name5566/leaf/log"
)
// 服务器结构
var Server struct {
LogLevel string
LogPath string
WSAddr string
CertFile string
KeyFile string
TCPAddr string
MaxConnNum int
ConsolePort int
ProfilePath string
}
// 加载服务器配置
func init() {
data, err := ioutil.ReadFile("conf/server.json")
if err != nil {
log.Fatal("%v", err)
}
err = json.Unmarshal(data, &Server)
if err != nil {
log.Fatal("%v", err)
}
}
复制代码
从源码中可以看到 配置文件是加载conf/server.json的json的文件
![](http://www.golang.ltd/data/attachment/forum/201711/07/081234nriwrztf22rvvibf.png)
配置文件的json结构
// 服务器结构
var Server struct {
LogLevel string
LogPath string
WSAddr string
CertFile string
KeyFile string
TCPAddr string
MaxConnNum int
ConsolePort int
ProfilePath string
}
复制代码
先分析到这里,下节我们添加json文件,后启动server,测试下本地可以连接不。
原文地址 leaf开源服务器-分析1
首先,leaf开源服务器-大多数网上文章介绍都是关于游戏服务器的;其实总体框架来说,做H5聊天服务器也可以的;同时leaf总体设计来说,个人认为此框架不仅仅适合游戏。
项目入口
![](http://www.golang.ltd/data/attachment/forum/201711/07/080859hsl8z68ysyymyoey.png)
main.go
package main
import (
"server/conf"
"server/game"
"server/gate"
"server/login"
"github.com/name5566/leaf"
lconf "github.com/name5566/leaf/conf"
)
func main() {
// 加载配置
lconf.LogLevel = conf.Server.LogLevel
lconf.LogPath = conf.Server.LogPath
lconf.LogFlag = conf.LogFlag
lconf.ConsolePort = conf.Server.ConsolePort
lconf.ProfilePath = conf.Server.ProfilePath
// 运行
leaf.Run(
game.Module,
gate.Module,
login.Module,
)
}
复制代码
从主函数分析
// 加载配置
lconf.LogLevel = conf.Server.LogLevel
lconf.LogPath = conf.Server.LogPath
lconf.LogFlag = conf.LogFlag
lconf.ConsolePort = conf.Server.ConsolePort
lconf.ProfilePath = conf.Server.ProfilePath
复制代码
加载配置文件,配置文件在哪里?
![](http://www.golang.ltd/data/attachment/forum/201711/07/081047cxvvpy349vyx3xh4.png)
json.go 源码
package conf
import (
"encoding/json"
"io/ioutil"
"github.com/name5566/leaf/log"
)
// 服务器结构
var Server struct {
LogLevel string
LogPath string
WSAddr string
CertFile string
KeyFile string
TCPAddr string
MaxConnNum int
ConsolePort int
ProfilePath string
}
// 加载服务器配置
func init() {
data, err := ioutil.ReadFile("conf/server.json")
if err != nil {
log.Fatal("%v", err)
}
err = json.Unmarshal(data, &Server)
if err != nil {
log.Fatal("%v", err)
}
}
复制代码
从源码中可以看到 配置文件是加载conf/server.json的json的文件
![](http://www.golang.ltd/data/attachment/forum/201711/07/081234nriwrztf22rvvibf.png)
配置文件的json结构
// 服务器结构
var Server struct {
LogLevel string
LogPath string
WSAddr string
CertFile string
KeyFile string
TCPAddr string
MaxConnNum int
ConsolePort int
ProfilePath string
}
复制代码
先分析到这里,下节我们添加json文件,后启动server,测试下本地可以连接不。
原文地址 leaf开源服务器-分析1
相关文章推荐
- leaf开源服务器第四节-分析源码实现模拟TCP客户端
- leaf开源服务器第三节-分析TCP消息通信之增加Glog日志(1)
- leaf开源服务器第二节-分析之配置文件说明及服务器运行
- 基于.NET 2.0的GIS开源项目SharpMap分析手记(二):源代码总体结构分析
- IM 开源项目 登录服务器 基础表结构<2>
- 基于.NET 2.0的GIS开源项目SharpMap分析手记(二):源代码总体结构分析
- jiecaovideo开源项目笔记-JCVideoPlayer分析-小屏逻辑
- ABP源码分析一:整体项目结构及目录
- jeecms2012 框架分析 Spring mvc+hibernate+freemarker(开源项目)
- 2013年6月8日 -- 最近喜欢上了分析开源项目,赶脚有点走火入魔了...
- 开源项目kcws代码分析--基于深度学习的分词技术
- YII高级项目模板目录结构分析
- Android项目目录结构分析
- Leaf - 一个由 Go 语言编写的开发效率和执行效率并重的开源游戏服务器框架
- Android基础之项目结构分析
- Mustache php 版开源项目 流程 性能分析 以及优化
- PHP开源项目二次开发前期分析方法
- Android 项目eclipse、Android Studio目录结构分析
- 开源项目分析之UIL(续)
- 开源ERP的精华-OpenBravo 数据库结构基本分析