Skip to content

Commit

Permalink
...
Browse files Browse the repository at this point in the history
  • Loading branch information
wubin1989 committed Jan 13, 2022
1 parent 444ac9f commit 29a3081
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 7 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,8 @@ It also provided a `Init` function to help you configure `logrus.Logger` instanc
You can also configure log level by environment variable `GDD_LOG_LEVEL` and configure formatter type to `json` or `text` by environment variable `GDD_LOG_FORMAT`.
There are two built-in log related middlewares for you, `ddhttp.Metrics` and `ddhttp.Logger`. In short, `ddhttp.Metrics` is for printing brief log with limited
information, while `ddhttp.Logger` is for printing detail log with request and response body, headers, opentracing span and some other information.
information, while `ddhttp.Logger` is for printing detail log with request and response body, headers, opentracing span and some other information, and it only takes
effect when environment variable `GDD_LOG_LEVEL` is set to `debug`.
#### Example
```go
Expand Down
3 changes: 2 additions & 1 deletion svc/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ func Test_envVariable_Write(t *testing.T) {
}

func Test_envVariable_String(t *testing.T) {
GddBanner.Write("on")
tests := []struct {
name string
receiver envVariable
Expand All @@ -220,7 +221,7 @@ func Test_envVariable_String(t *testing.T) {
{
name: "",
receiver: GddBanner,
want: "GDD_BANNER",
want: "on",
},
}
for _, tt := range tests {
Expand Down
2 changes: 1 addition & 1 deletion svc/http/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func Logger(inner http.Handler) http.Handler {
}
var log string
if log, err = jsonMarshalIndent(fields, "", " ", true); err != nil {
log = fmt.Sprintf("call jsonMarshalIndent(fields, \"\", \" \", true) error: ", err)
log = fmt.Sprintf("call jsonMarshalIndent(fields, \"\", \" \", true) error: %s", err)
}
logger.WithFields(fields).Debugln(log)

Expand Down
2 changes: 1 addition & 1 deletion svc/internal/codegen/testdata/usersvc_openapi3.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ package service
import "github.com/unionj-cloud/go-doudou/svc/http/onlinedoc"

func init() {
onlinedoc.Oas = `{"openapi":"3.0.2","info":{"title":"Usersvc","description":"用户服务接口\nv1版本","version":"v20220111"},"paths":{"/usersvc/downloadavatar":{"post":{"description":"comment5","requestBody":{"content":{"application/x-www-form-urlencoded":{"schema":{"$ref":"#/components/schemas/DownloadAvatarReq"}}},"required":true},"responses":{"200":{"content":{"application/octet-stream":{"schema":{"type":"string","format":"binary"}}}}}}},"/usersvc/pageusers":{"post":{"description":"You can define your service methods as your need. Below is an example.","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/PageQuery"}}},"required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/PageUsersResp"}}}}}}},"/usersvc/signup":{"post":{"description":"comment3","requestBody":{"content":{"application/x-www-form-urlencoded":{"schema":{"$ref":"#/components/schemas/SignUpReq"}}},"required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/SignUpResp"}}}}}}},"/usersvc/uploadavatar":{"post":{"description":"comment4","requestBody":{"content":{"multipart/form-data":{"schema":{"$ref":"#/components/schemas/UploadAvatarReq"}}},"required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/UploadAvatarResp"}}}}}}},"/usersvc/user":{"get":{"description":"comment1\ncomment2","parameters":[{"name":"userId","in":"query","description":"用户ID","schema":{"type":"string","description":"用户ID"}},{"name":"photo","in":"query","description":"图片地址","schema":{"type":"string","description":"图片地址"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/GetUserResp"}}}}}}}},"components":{"schemas":{"DownloadAvatarReq":{"title":"DownloadAvatarReq","type":"object","properties":{"userId":{"type":"string"}}},"Event":{"title":"Event","type":"object","properties":{"EventType":{"type":"integer","format":"int32"},"Name":{"type":"string"}}},"GetUserResp":{"title":"GetUserResp","type":"object","properties":{"code":{"type":"integer","format":"int32"},"data":{"type":"string"},"msg":{"type":"string"}}},"Order":{"title":"Order","type":"object","properties":{"Col":{"type":"string"},"Sort":{"type":"string"}},"description":"排序条件"},"Page":{"title":"Page","type":"object","properties":{"Orders":{"type":"array","items":{"$ref":"#/components/schemas/Order"},"description":"排序规则"},"PageNo":{"type":"integer","format":"int32","description":"页码"},"Size":{"type":"integer","format":"int32","description":"每页行数"},"User":{"$ref":"#/components/schemas/UserVo"}}},"PageFilter":{"title":"PageFilter","type":"object","properties":{"Dept":{"type":"integer","format":"int32","description":"所属部门ID"},"Name":{"type":"string","description":"真实姓名,前缀匹配"}},"description":"筛选条件"},"PageQuery":{"title":"PageQuery","type":"object","properties":{"Filter":{"$ref":"#/components/schemas/PageFilter"},"Page":{"$ref":"#/components/schemas/Page"}},"description":"分页筛选条件"},"PageRet":{"title":"PageRet","type":"object","properties":{"HasNext":{"type":"boolean"},"Items":{"type":"object"},"PageNo":{"type":"integer","format":"int32"},"PageSize":{"type":"integer","format":"int32"},"Total":{"type":"integer","format":"int32"}}},"PageUsersResp":{"title":"PageUsersResp","type":"object","properties":{"code":{"type":"integer","format":"int32"},"data":{"$ref":"#/components/schemas/PageRet"},"msg":{"type":"string"}}},"SignUpReq":{"title":"SignUpReq","type":"object","properties":{"actived":{"type":"boolean"},"password":{"type":"integer","format":"int32"},"score":{"type":"array","items":{"type":"integer","format":"int32"}},"username":{"type":"string"}}},"SignUpResp":{"title":"SignUpResp","type":"object","properties":{"code":{"type":"integer","format":"int32"},"data":{"type":"string"},"msg":{"type":"string"}}},"TestAlias":{"title":"TestAlias","type":"object","properties":{"Age":{"type":"object"},"School":{"type":"array","items":{"type":"object","properties":{"Addr":{"type":"object","properties":{"Block":{"type":"string"},"Full":{"type":"string"},"Zip":{"type":"string"}}},"Name":{"type":"string"}}}}}},"UploadAvatarReq":{"title":"UploadAvatarReq","type":"object","properties":{"pf":{"type":"array","items":{"type":"string","format":"binary"}},"pf2":{"type":"string","format":"binary"},"pf3":{"type":"string","format":"binary"},"pf4":{"type":"array","items":{"type":"string","format":"binary"}},"ps":{"type":"string"}}},"UploadAvatarResp":{"title":"UploadAvatarResp","type":"object","properties":{"re":{"type":"string"},"ri":{"type":"integer","format":"int32"},"rs":{"type":"string"}}},"UserVo":{"title":"UserVo","type":"object","properties":{"Dept":{"type":"string"},"Id":{"type":"integer","format":"int32"},"Name":{"type":"string"},"Phone":{"type":"string"}}}}}}`
onlinedoc.Oas = `{"openapi":"3.0.2","info":{"title":"Usersvc","description":"用户服务接口\nv1版本","version":"v20220113"},"paths":{"/usersvc/downloadavatar":{"post":{"description":"comment5","requestBody":{"content":{"application/x-www-form-urlencoded":{"schema":{"$ref":"#/components/schemas/DownloadAvatarReq"}}},"required":true},"responses":{"200":{"content":{"application/octet-stream":{"schema":{"type":"string","format":"binary"}}}}}}},"/usersvc/pageusers":{"post":{"description":"You can define your service methods as your need. Below is an example.","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/PageQuery"}}},"required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/PageUsersResp"}}}}}}},"/usersvc/signup":{"post":{"description":"comment3","requestBody":{"content":{"application/x-www-form-urlencoded":{"schema":{"$ref":"#/components/schemas/SignUpReq"}}},"required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/SignUpResp"}}}}}}},"/usersvc/uploadavatar":{"post":{"description":"comment4","requestBody":{"content":{"multipart/form-data":{"schema":{"$ref":"#/components/schemas/UploadAvatarReq"}}},"required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/UploadAvatarResp"}}}}}}},"/usersvc/user":{"get":{"description":"comment1\ncomment2","parameters":[{"name":"userId","in":"query","description":"用户ID","schema":{"type":"string","description":"用户ID"}},{"name":"photo","in":"query","description":"图片地址","schema":{"type":"string","description":"图片地址"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/GetUserResp"}}}}}}}},"components":{"schemas":{"DownloadAvatarReq":{"title":"DownloadAvatarReq","type":"object","properties":{"userId":{"type":"string"}}},"Event":{"title":"Event","type":"object","properties":{"EventType":{"type":"integer","format":"int32"},"Name":{"type":"string"}}},"GetUserResp":{"title":"GetUserResp","type":"object","properties":{"code":{"type":"integer","format":"int32"},"data":{"type":"string"},"msg":{"type":"string"}}},"Order":{"title":"Order","type":"object","properties":{"Col":{"type":"string"},"Sort":{"type":"string"}},"description":"排序条件"},"Page":{"title":"Page","type":"object","properties":{"Orders":{"type":"array","items":{"$ref":"#/components/schemas/Order"},"description":"排序规则"},"PageNo":{"type":"integer","format":"int32","description":"页码"},"Size":{"type":"integer","format":"int32","description":"每页行数"},"User":{"$ref":"#/components/schemas/UserVo"}}},"PageFilter":{"title":"PageFilter","type":"object","properties":{"Dept":{"type":"integer","format":"int32","description":"所属部门ID"},"Name":{"type":"string","description":"真实姓名,前缀匹配"}},"description":"筛选条件"},"PageQuery":{"title":"PageQuery","type":"object","properties":{"Filter":{"$ref":"#/components/schemas/PageFilter"},"Page":{"$ref":"#/components/schemas/Page"}},"description":"分页筛选条件"},"PageRet":{"title":"PageRet","type":"object","properties":{"HasNext":{"type":"boolean"},"Items":{"type":"object"},"PageNo":{"type":"integer","format":"int32"},"PageSize":{"type":"integer","format":"int32"},"Total":{"type":"integer","format":"int32"}}},"PageUsersResp":{"title":"PageUsersResp","type":"object","properties":{"code":{"type":"integer","format":"int32"},"data":{"$ref":"#/components/schemas/PageRet"},"msg":{"type":"string"}}},"SignUpReq":{"title":"SignUpReq","type":"object","properties":{"actived":{"type":"boolean"},"password":{"type":"integer","format":"int32"},"score":{"type":"array","items":{"type":"integer","format":"int32"}},"username":{"type":"string"}}},"SignUpResp":{"title":"SignUpResp","type":"object","properties":{"code":{"type":"integer","format":"int32"},"data":{"type":"string"},"msg":{"type":"string"}}},"TestAlias":{"title":"TestAlias","type":"object","properties":{"Age":{"type":"object"},"School":{"type":"array","items":{"type":"object","properties":{"Addr":{"type":"object","properties":{"Block":{"type":"string"},"Full":{"type":"string"},"Zip":{"type":"string"}}},"Name":{"type":"string"}}}}}},"UploadAvatarReq":{"title":"UploadAvatarReq","type":"object","properties":{"pf":{"type":"array","items":{"type":"string","format":"binary"}},"pf2":{"type":"string","format":"binary"},"pf3":{"type":"string","format":"binary"},"pf4":{"type":"array","items":{"type":"string","format":"binary"}},"ps":{"type":"string"}}},"UploadAvatarResp":{"title":"UploadAvatarResp","type":"object","properties":{"re":{"type":"string"},"ri":{"type":"integer","format":"int32"},"rs":{"type":"string"}}},"UserVo":{"title":"UserVo","type":"object","properties":{"Dept":{"type":"string"},"Id":{"type":"integer","format":"int32"},"Name":{"type":"string"},"Phone":{"type":"string"}}}}}}`
}
Loading

0 comments on commit 29a3081

Please sign in to comment.