作者 yangfu

Merge remote-tracking branch 'origin/dev'

... ... @@ -14,7 +14,7 @@ require (
//github.com/opentracing/opentracing-go v1.1.1-0.20190913142402-a7454ce5950e
//github.com/openzipkin-contrib/zipkin-go-opentracing v0.4.5
//github.com/openzipkin/zipkin-go v0.2.5
github.com/tiptok/gocomm v1.0.4
github.com/tiptok/gocomm v1.0.6
)
//replace github.com/tiptok/gocomm v1.0.3 => F:\go\src\learn_project\gocomm
//replace github.com/tiptok/gocomm v1.0.5 => F:\go\src\learn_project\gocomm
... ...
package main
import (
"fmt"
"github.com/astaxie/beego"
"github.com/tiptok/gocomm/config"
"github.com/tiptok/gocomm/pkg/cache"
"github.com/tiptok/gocomm/pkg/log"
"github.com/tiptok/gocomm/pkg/redis"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/constant"
_ "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/constant"
_ "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/infrastructure/pg"
_ "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/infrastructure/redis"
_ "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/port/beego"
//logx "log"
)
func main() {
... ... @@ -22,6 +26,12 @@ func main() {
Level: constant.LOG_LEVEL,
})
cache.InitDefault(cache.WithDefaultRedisPool(redis.GetRedisPool()), cache.WithDebugLog(true, log.DefaultLog), cache.WithDeleteChannel(fmt.Sprintf("%v_%v", constant.POSTGRESQL_DB_NAME, "delkey")))
//log.DefaultLog = console.NewConsoleLog(config.Logger{
// Filename: constant.LOG_File,
// Level: constant.LOG_LEVEL,
//}, fmt.Sprintf("[%v]", constant.POSTGRESQL_DB_NAME), 3)
//{
// // set up a span reporter
// reporter := zipkinhttp.NewReporter("http://106.52.15.41:9411/api/v2/spans")
... ...
... ... @@ -5,6 +5,7 @@ import (
"github.com/tiptok/gocomm/pkg/cache"
"github.com/tiptok/gocomm/pkg/log"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/application/factory"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/constant"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/domain"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/infrastructure/dao"
"regexp"
... ... @@ -13,7 +14,7 @@ import (
//redis key
func UserRoleAccessCacheKey(userId int64) string {
return fmt.Sprintf("godevp:user:access:%v", userId)
return fmt.Sprintf("%v:user:access:%v", constant.POSTGRESQL_DB_NAME, userId)
}
type CacheService struct {
... ...
... ... @@ -2,7 +2,6 @@ package redis
import (
"fmt"
"github.com/tiptok/gocomm/pkg/cache"
"github.com/tiptok/gocomm/pkg/log"
"github.com/tiptok/gocomm/pkg/redis"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/constant"
... ... @@ -14,5 +13,4 @@ func init() {
if err != nil {
log.Error(err)
}
cache.InitDefault(cache.WithDefaultRedisPool(redis.GetRedisPool()))
}
... ...
... ... @@ -6,6 +6,7 @@ import (
"github.com/tiptok/gocomm/common"
"github.com/tiptok/gocomm/pkg/cache"
. "github.com/tiptok/gocomm/pkg/orm/pgx"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/constant"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/domain"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/infrastructure/pg/transaction"
... ... @@ -13,7 +14,7 @@ import (
var (
cacheRoleIdKey = func(id int64) string {
return fmt.Sprintf("%v:cache:Role:id:%v", "godevp", id)
return fmt.Sprintf("%v:cache:Role:id:%v", constant.POSTGRESQL_DB_NAME, id)
}
)
... ...
... ... @@ -5,6 +5,7 @@ import (
"github.com/tiptok/gocomm/common"
"github.com/tiptok/gocomm/pkg/cache"
. "github.com/tiptok/gocomm/pkg/orm/pgx"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/constant"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/domain"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/infrastructure/pg/transaction"
... ... @@ -12,7 +13,7 @@ import (
var (
cacheUsersIdKey = func(id int64) string {
return fmt.Sprintf("%v:cache:Users:id:%v", "godevp", id)
return fmt.Sprintf("%v:cache:Users:id:%v", constant.POSTGRESQL_DB_NAME, id)
}
)
... ...
package log
import (
"fmt"
"github.com/astaxie/beego/logs"
"github.com/tiptok/gocomm/config"
logx "github.com/tiptok/gocomm/pkg/log"
"log"
"strings"
)
type ConsoleLog struct {
//log *log.Logger
config config.Logger
depth int
level int
}
func NewConsoleLog(config config.Logger, prefix string, depth int) logx.Log {
if len(prefix) > 0 {
log.SetPrefix(prefix)
}
log.SetFlags(log.LstdFlags | log.Lshortfile)
return &ConsoleLog{
config: config,
depth: depth,
level: beegoLogLevelAdapter(config.Level),
}
}
func (this *ConsoleLog) Debug(args ...interface{}) {
if this.level < logs.LevelDebug {
return
}
log.Output(this.depth, this.appendAhead(args, "[D]"))
}
func (this *ConsoleLog) Info(args ...interface{}) {
if this.level < logs.LevelInfo {
return
}
log.Output(this.depth, this.appendAhead(args, "[I]"))
}
func (this *ConsoleLog) Warn(args ...interface{}) {
if this.level < logs.LevelWarning {
return
}
log.Output(this.depth, this.appendAhead(args, "[W]"))
}
func (this *ConsoleLog) Error(args ...interface{}) {
if this.level < logs.LevelError {
return
}
log.Output(this.depth, this.appendAhead(args, "[E]"))
}
func (this *ConsoleLog) Panic(args ...interface{}) {
log.Output(this.depth, this.appendAhead(args, "[P]"))
}
func (this *ConsoleLog) Fatal(args ...interface{}) {
log.Output(this.depth, this.appendAhead(args, "[F]"))
}
func (this *ConsoleLog) appendAhead(args []interface{}, addArgs ...interface{}) string {
var rsp []interface{}
rsp = append(rsp, addArgs...)
rsp = append(rsp, args...)
return fmt.Sprint(rsp...)
}
func beegoLogLevelAdapter(logLevel string) int {
switch strings.ToUpper(logLevel) {
case "DEBUG":
return logs.LevelDebug
case "INFO":
return logs.LevelInformational
case "WARN":
return logs.LevelWarning
case "ERROR":
return logs.LevelError
}
return logs.LevelDebug
}
... ...
package middleware
import (
"bufio"
"bytes"
"encoding/json"
"errors"
"fmt"
"github.com/astaxie/beego/context"
"io"
//"github.com/opentracing/opentracing-go"
auth "github.com/abbot/go-http-auth"
"github.com/tiptok/gocomm/common"
"github.com/tiptok/gocomm/gs"
"github.com/tiptok/gocomm/pkg/log"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/application/cachex"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol"
... ... @@ -172,3 +177,36 @@ func BasicAuth() func(ctx *context.Context) {
}
}
}
// http://127.0.0.1:8080/logf?source=dev/2021-01-08/mmmgodevp.2021-01-08.dev.txt
func LogF() func(ctx *context.Context) {
return func(ctx *context.Context) {
source := ctx.Input.Query("source")
client := gs.NewGateWayClient("http://dockerlogs.fjmaimaimai.com/")
client.AddApi("log", source, "")
request := client.NewRequest("log")
rsp, err := request.Response()
if err != nil {
ctx.Output.SetStatus(http.StatusInternalServerError)
ctx.Output.Body([]byte(source))
return
}
type LogInfo struct {
LogContent string `json:"log"`
}
buf := bufio.NewReader(rsp.Body)
rspData := bytes.NewBuffer(nil)
for {
data, _, err := buf.ReadLine()
if err == io.EOF || err != nil {
break
}
logItem := &LogInfo{}
common.JsonUnmarshal(string(data), logItem)
rspData.WriteString(logItem.LogContent)
}
ctx.Output.Body(rspData.Bytes())
ctx.Output.ContentType("text/plain; charset=utf-8")
}
}
... ...
... ... @@ -3,8 +3,11 @@ package routers
import (
"github.com/astaxie/beego"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/constant"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/port/beego/middleware"
)
func init() {
beego.SetStaticPath("/log", constant.LOG_File)
beego.Get("/logf", middleware.LogF())
}
... ...
## 1. 客户端工具下载
### 1.1 版本 v0.1.0
https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20201228/object/1609137707_XsBEXcRxJscRHCzQmxeseTAEQXTH7A7Z.zip
## 2. 账号登录
账号需要向平台服务申请,用户名为 申请人手机号 默认密码 mmm123456
![image-20201231152315657](https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20210113/object/1610504740_smhbM5mmBrHjpytcydMNs2xm4AKjA2xY.png)
## 3. 项目初始化
设置项目/描述文件路径
![image-20201231152940513](https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20210113/object/1610504746_eTAEQXTH7A7ZK6z4FzZ2YeDwX3KwcGdD.png)
## 4. 应用描述文件生成
### 4.1 添加属性描述 (attribute)
![image-20201231153445643](https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20210113/object/1610504750_tEYHSbtbSdasD2PM4QGX3yZtx33xATYN.png)
属性是描述文件的最小单元
attibute名称
```
例如此处 taskId
属性名称会影响到描述文件的文件名称,这边会生成的描述文件
taskId.yaml
```
attribute类型 包含
```
primitive: 原始类型,包括:string,boolean,int,int32,int64,uint,uint32,uint64,float32,float64,datetime,bytes
array: 原始类型数组,或者自定义模式数组,例子:string或者task
schema: 自定义模式,Schema描述的name字段,例子:task
```
attribute 所在文件名称
```
例如此处 task
生成的描述文件就会保存在 /task/taskId.yaml
```
文件内容如下
```
version: v1
kind: Attribute
metadata:
name: taskId
description: 任务编号
type:
primitive: int64
```
### 4.2 添加结构描述(schema)
![image-20201231155037423](https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20210113/object/1610504756_dFnFtQKEHHxJknQFEAK5rmXDfSrhxjA7.png)
生成描述文件 /schemas/task.yaml
```
version: v1
kind: Schema
metadata:
name: task
description: 任务实体
attributes:
- ref: taskId
required: true
- ref: taskName
required: true
- name: taskDescription
description: 任务描述-(这边写入自定义属性的描述)
type:
primitive: string
```
### 4.3 添加服务描述 (service)
![image-20201231155415791](https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20210113/object/1610504761_er4FArQSQfbbxQPBPnFDeRabpJ3k7kzS.png)
method名称 :指定CURD 工具会自动生成服务方法 create、get、list、remove、update
```
F:\eggcode\dsl\godevp\services\task\methods\createTask.yaml
F:\eggcode\dsl\godevp\services\task\methods\getTask.yaml
F:\eggcode\dsl\godevp\services\task\methods\listTask.yaml
F:\eggcode\dsl\godevp\services\task\methods\removeTask.yaml
F:\eggcode\dsl\godevp\services\task\methods\updateTask.yaml
F:\eggcode\dsl\godevp\services\task\service.yaml
```
### 4.4 添加接口描述(api)
![image-20201231161927395](https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20210113/object/1610504767_6tbPWDQksxsJKR5Gneb5AYJTABjkNEAG.png)
生成描述文件 /http/task.yaml
```
version: v1
kind: HttpApi
metadata:
service: task
path: /tasks
endpoints:
- method: createTask
route:
post: /
- method: updateTask
route:
put: /{taskId} ##注意这边需要手动加上task
- method: getTask
route:
get: /{taskId} ##注意这边需要手动加上task
- method: removeTask
route:
delete: /{taskId} ##注意这边需要手动加上task
- method: listTask
route:
get: /
params:
- name: offset
- name: limit
```
## 5. 生成项目代码
### 5.1 生成项目脚手架 (基础文件)
指定web框架、数据库
![image-20201231162224099](https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20210113/object/1610504772_dbtZePks2hW2nNAhX4CRCmwczeFaK5Gz.png)
### 5.2 生成领域模型 (domain相关文件)
![image-20201231163250901](https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20210113/object/1610504777_EnmnrTR7kA34XNFMPGeRFYJfcJ7pysry.png)
### 5.3 生成应用服务 (application)
![image-20201231163332731](https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20210113/object/1610504782_MXKXHYEbKsRskTyRGYkmFrdwfRHEMc33.png)
### 5.4 生成http服务文件(路由控制器)
![image-20201231163433314](https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20210113/object/1610504787_XC4dtwzeBhkCDt6CDF3QPJb2TMTBJyxc.png)
## 6. 生成文档
![image-20201231163458590](https://timeless-world.oss-cn-shenzhen.aliyuncs.com/open-api/dev_online/20210113/object/1610504792_DKThDyRJmAk3mt7j6ypM3BYxceC7AWzX.png)
\ No newline at end of file
... ...