Commit ccc869b9 by 孙龙

up

parent 69909ab5
Showing with 203 additions and 8 deletions
...@@ -8,14 +8,14 @@ git clone http://git.ichunt.net/sunlong_v5/golang_framework_demo.git ...@@ -8,14 +8,14 @@ git clone http://git.ichunt.net/sunlong_v5/golang_framework_demo.git
# 2.删除.git文件夹,重新初始化git # 2.删除.git文件夹(隐藏文件件),并重新初始化git
# 3.修改项目文件夹名称 # 3.修改项目文件夹名称
1.将 golang_framework_demo 改成 golang_framework_xxxxxxx 1.将 golang_framework_demo 改成 golang_framework_xxxxxxx(自己定义)
2.编辑器批量修改包名 : golang_framework_demo => golang_framework_xxxxxxx 2.**编辑器批量修改包名** : golang_framework_demo => golang_framework_xxxxxxx (自己定义)
...@@ -23,7 +23,7 @@ git clone http://git.ichunt.net/sunlong_v5/golang_framework_demo.git ...@@ -23,7 +23,7 @@ git clone http://git.ichunt.net/sunlong_v5/golang_framework_demo.git
一定要修改go.mod文件,要不然无法跑起来 一定要修改go.mod文件,要不然无法跑起来
把go.mod的第一行 : golang_framework_demo 修改成 golang_framework_xxxxxxx 把go.mod的第一行 : golang_framework_demo 修改成 golang_framework_xxxxxxx(自己定义)
# 5.修改http监听地址 # 5.修改http监听地址
...@@ -76,11 +76,12 @@ go run ./cmd/task/main.go -config=./config/dev/ -logdir=./logs/ ...@@ -76,11 +76,12 @@ go run ./cmd/task/main.go -config=./config/dev/ -logdir=./logs/
启动须知: ## 启动须知:
修改config/proxy.toml
修改启动端口: 修改config/**proxy.toml**
> 修改启动端口:
[http] [http]
...@@ -93,7 +94,7 @@ go run ./cmd/task/main.go -config=./config/dev/ -logdir=./logs/ ...@@ -93,7 +94,7 @@ go run ./cmd/task/main.go -config=./config/dev/ -logdir=./logs/
max_header_bytes = 20 # 最大的header大小,二进制位长度 max_header_bytes = 20 # 最大的header大小,二进制位长度
微服务注册相关信息修改 > 微服务注册相关信息修改
#服务注册名称 #服务注册名称
...@@ -101,6 +102,8 @@ micro_service_name = "golang_async_task_http" ...@@ -101,6 +102,8 @@ micro_service_name = "golang_async_task_http"
#etcd配置信息 etcd服务的ip端口用户密码 #etcd配置信息 etcd服务的ip端口用户密码
```
[etcd_config] [etcd_config]
addrs = [ addrs = [
"192.168.1.252:2379" "192.168.1.252:2379"
...@@ -108,12 +111,190 @@ micro_service_name = "golang_async_task_http" ...@@ -108,12 +111,190 @@ micro_service_name = "golang_async_task_http"
username = "" username = ""
password = "" password = ""
```
#注册到etcd中的ip 端口 权重信息 #注册到etcd中的ip 端口 权重信息
```
[etcd_regist] [etcd_regist]
ip = "192.168.1.252" ip = "192.168.1.252"
port = 60020 port = 60020
weight = 10 weight = 10
```
如无需负载均衡 则可以注释掉http/main.go中服务注册代码
```
//微服务注册
regist_etcd.Init()
```
# 路由:
router/route.go
```
func InitRouter(middlewares ...gin.HandlerFunc) *gin.Engine {
//todo 优化点1
//router := gin.Default()
router := gin.New()
router.Use(middlewares...)
router.GET("/ping", controller.Ping)
router.GET("/hbsdata",controller.Hbsdata)
router.POST("/callback", controller.Callback)
router.Use(
gin.Logger(),
)
return router
}
```
# 数据库配置
数据库采用xorm包
> 配置数据库
```
数据库配置文件路径:config/dev/db.toml
[async_task]
data_source_name = "lie_async_task:lie_async_task#zsyM@tcp(192.168.1.252:3306)/liexin_async_task?charset=utf8&parseTime=true&loc=Asia%2FShanghai"
max_open_conn = 20
max_idle_conn = 10
table_prefix = ""
max_conn_life_time = 100
添加数据库:app/common/config/http/mysql.go
//单、主数据 master
//async_task:数据库名(可以自己定义别名)
func BuildDatabaseList() (DatabaseList map[string]BaseDatabase) {
return map[string]BaseDatabase{
"async_task": {
DataSourceName: lib.Instance("db").GetString("async_task.data_source_name"),//数据库名
Prefix: lib.Instance("db").GetString("async_task.table_prefix"),//前缀
MaxIdleCons:lib.Instance("db").GetInt("async_task.max_idle_conn"),////设置连接池的空闲数大小
MaxOpenCons:lib.Instance("db").GetInt("async_task.max_open_conn"),//设置最大打开连接数
},
}
}
数据库配置路径:config/dev/db.toml
[liexin]
max_open_conn = 20
max_idle_conn = 10
table_prefix = ""
max_conn_life_time = 100
data_source_name = [
"micro_service:lie_micro_service#zsyM@tcp(192.168.1.252:3306)/lie_micro_service?charset=utf8&parseTime=true&loc=Asia%2FChongqing",
"micro_service:lie_micro_service#zsyM@tcp(192.168.1.252:3306)/lie_micro_service?charset=utf8&parseTime=true&loc=Asia%2FChongqing",
"micro_service:lie_micro_service#zsyM@tcp(192.168.1.252:3306)/lie_micro_service?charset=utf8&parseTime=true&loc=Asia%2FChongqing",
]
//主从数据 master slave
func BuildGroupDatabaseList() (DatabaseList map[string]GroupDatabase) {
return map[string]GroupDatabase{
//"liexin": {
// DataSourceName:lib.Instance("db").GetStringSlice("liexin.data_source_name"),
// Prefix: lib.Instance("db").GetString("liexin.table_prefix"),
// MaxIdleCons:lib.Instance("db").GetInt("liexin.max_idle_conn"),
// MaxOpenCons:lib.Instance("db").GetInt("liexin.max_open_conn"),
//},
}
}
```
# redis配置
```
redis配置文件路径 config/dev/redis.toml
[api]
dial_timeout = 20
min_idle_conns = 10
read_timeout = 10
write_timeout = 10
[api.master]
host = "192.168.1.235:6379"
password = "icDb29mLy2s"
[api.slave]
password = "icDb29mLy2s"
host = [
"192.168.1.235:6379",
"192.168.1.237:6379",
]
添加redis数据库 :app/common/config/http/redis.go
//多数据库配置
func BuildRedisGroupConfigs() ( map[string]RedisGroupDatabase) {
//fmt.Println("6666666666")
//fmt.Println(lib.Instance("redis").GetStringSlice("api.slave.host"))
return map[string]RedisGroupDatabase{
"api": {
MasterHost: lib.Instance("redis").GetString("api.master.host"),
Password:lib.Instance("redis").GetString("api.master.password"),
SlaveHost: lib.Instance("redis").GetStringSlice("api.slave.host"),
ReadonlyPassword:lib.Instance("redis").GetString("api.slave.password"),
DialTimeout: time.Duration(lib.Instance("redis").GetInt("api.dial_timeout"))*time.Second,
ReadTimeout: time.Duration(lib.Instance("redis").GetInt("api.read_timeout"))*time.Second,
WriteTimeout: time.Duration(lib.Instance("redis").GetInt("api.write_timeout"))*time.Second,
MinIdleConns:lib.Instance("redis").GetInt("api.min_idle_conns"),
},
"sku": {
MasterHost: lib.Instance("redis").GetString("sku.master.host"),
Password:lib.Instance("redis").GetString("sku.master.password"),
SlaveHost: lib.Instance("redis").GetStringSlice("sku.slave.host"),
ReadonlyPassword:lib.Instance("redis").GetString("sku.slave.password"),
DialTimeout: time.Duration(lib.Instance("redis").GetInt("sku.dial_timeout"))*time.Second,
ReadTimeout: time.Duration(lib.Instance("redis").GetInt("sku.read_timeout"))*time.Second,
WriteTimeout: time.Duration(lib.Instance("redis").GetInt("sku.write_timeout"))*time.Second,
MinIdleConns:lib.Instance("redis").GetInt("sku.min_idle_conns"),
},
}
}
```
...@@ -123,8 +304,22 @@ micro_service_name = "golang_async_task_http" ...@@ -123,8 +304,22 @@ micro_service_name = "golang_async_task_http"
参考文献: 参考文献:
mysql:
xorm:https://www.kancloud.cn/xormplus/xorm/413729 xorm:https://www.kancloud.cn/xormplus/xorm/413729
redis:
go-redis-pool https://github.com/ichunt2019/go-redis-pool go-redis-pool https://github.com/ichunt2019/go-redis-pool
配置文件
github.com/ichunt2019/lxLog
日志包
github.com/ichunt2019/lxLog
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment