go-eagle / eagle Goto Github PK
View Code? Open in Web Editor NEW🦅 A Go framework for the API or Microservice
Home Page: https://go-eagle.org
License: MIT License
🦅 A Go framework for the API or Microservice
Home Page: https://go-eagle.org
License: MIT License
问题:在orm.go 文件中,如何优雅的配置,连接多数据库,读写分离,求解
场景:在生产环境,会出现读写分离,多数据库场景
1、db_user库下user表
2、db_order库下order表
请教一下,希望得到解答
感谢作者的贡献。希望能看到更多go 测试相关的 demo。我目前有两个疑惑
谢谢。
报错信息:
2020/10/09 16:03:36 [Recovery] 2020/10/09 - 16:03:36 panic recovered:
GET /register HTTP/1.1
Host: 127.0.0.1:8081
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Accept-Encoding: gzip, deflate, br
Accept-Language: zh-CN,zh;q=0.9,zh-TW;q=0.8,en;q=0.7
Connection: keep-alive
Referer: http://127.0.0.1:8081/
Sec-Fetch-Dest: document
Sec-Fetch-Mode: navigate
Sec-Fetch-Site: same-origin
Sec-Fetch-User: ?1
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36
TemplateEngine render read name:error/404, path:/Users/weiwang/go/src/snake/internal/templates/error/404.html, error: open /Users/weiwang/go/src/snake/internal/templates/error/404.html: no such file or directory
/Users/weiwang/go/pkg/mod/github.com/gin-gonic/[email protected]/context.go:842 (0x17911f2)
(*Context).Render: panic(err)
/Users/weiwang/go/pkg/mod/github.com/gin-gonic/[email protected]/context.go:851 (0x1791298)
(*Context).HTML: c.Render(code, instance)
/Users/weiwang/go/src/snake/app/web/error.go:10 (0x199c85d)
Error404: c.HTML(http.StatusOK, "error/404", gin.H{
/Users/weiwang/go/src/snake/router/web.go:25 (0x199c771)
LoadWebRouter.func1: web.Error404(c)
/Users/weiwang/go/pkg/mod/github.com/gin-gonic/[email protected]/context.go:161 (0x178d3ba)
(*Context).Next: c.handlers[c.index](c)
/Users/weiwang/go/src/snake/router/middleware/requestid.go:25 (0x1990c71)
RequestID.func1: c.Next()
/Users/weiwang/go/pkg/mod/github.com/gin-gonic/[email protected]/context.go:161 (0x178d3ba)
(*Context).Next: c.handlers[c.index](c)
/Users/weiwang/go/src/snake/router/middleware/header.go:24 (0x198fa9c)
Options: c.Next()
/Users/weiwang/go/pkg/mod/github.com/gin-gonic/[email protected]/context.go:161 (0x178d3ba)
(*Context).Next: c.handlers[c.index](c)
/Users/weiwang/go/src/snake/router/middleware/header.go:16 (0x198fa46)
NoCache: c.Next()
/Users/weiwang/go/pkg/mod/github.com/gin-gonic/[email protected]/context.go:161 (0x178d3ba)
(*Context).Next: c.handlers[c.index](c)
/Users/weiwang/go/pkg/mod/github.com/gin-gonic/[email protected]/recovery.go:83 (0x17a1273)
RecoveryWithWriter.func1: c.Next()
/Users/weiwang/go/pkg/mod/github.com/gin-gonic/[email protected]/context.go:161 (0x178d3ba)
(*Context).Next: c.handlers[c.index](c)
/Users/weiwang/go/pkg/mod/github.com/gin-gonic/[email protected]/logger.go:241 (0x17a03a0)
LoggerWithConfig.func1: c.Next()
/Users/weiwang/go/pkg/mod/github.com/gin-gonic/[email protected]/context.go:161 (0x178d3ba)
(*Context).Next: c.handlers[c.index](c)
/Users/weiwang/go/pkg/mod/github.com/gin-gonic/[email protected]/gin.go:445 (0x1797747)
serveError: c.Next()
/Users/weiwang/go/pkg/mod/github.com/gin-gonic/[email protected]/gin.go:438 (0x179739f)
(*Engine).handleHTTPRequest: serveError(c, http.StatusNotFound, default404Body)
/Users/weiwang/go/pkg/mod/github.com/gin-gonic/[email protected]/gin.go:367 (0x1796d2d)
(*Engine).ServeHTTP: engine.handleHTTPRequest(c)
/usr/local/go/src/net/http/server.go:2802 (0x14093d3)
serverHandler.ServeHTTP: handler.ServeHTTP(rw, req)
/usr/local/go/src/net/http/server.go:1890 (0x1404c74)
(*conn).serve: serverHandler{c.server}.ServeHTTP(w, w.req)
/usr/local/go/src/runtime/asm_amd64.s:1357 (0x1061280)
goexit: BYTE $0x90 // NOP
此外,我发现使用 db.sql 导入数据库会报错,不清楚是否有关系?
Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
Describe the solution you'd like
A clear and concise description of what you want to happen.
Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.
Additional context
Add any other context or screenshots about the feature request here.
这边我看到 dao 层的测试,想知道 svc 怎么测试,有没有示例
windows下如何启动
看起来 只支持 mysql. 是否 支持 postgresql ?
1、在model的init.go里64行,conn_max_lift_time写错了,应该是conn_max_life_time。
2、在config.sample.yaml中关于max_idle_conn和max_open_conn的注解好像是写反了。
请问一下有没有交流群之类的
目前的结构在service层写了所有的方法,每次调用时会比较难找到自己想要的方法
比如 目前的架构中 定义了
var (
UserSvc *Service
VCodeSvc *Service
)
但是在handler中调用service.UserSvc时,ide也会提示VCodeSvc下的相关方法,有优化的方式吗
这个是不是有违封装性,sql 代码是不是要放到 dao 层去
2021/10/29 07:22:55 ParseConfig: 1 error(s) decoding:
[app builder 10/10] RUN make build:
2.045 /go/pkg/mod/golang.org/x/[email protected]/http2/transport.go:19:2: package io/fs is not in GOROOT (/usr/local/go/src/io/fs)
2.047 make: *** [Makefile:31: build] Error 1
failed to solve: executor failed running [/bin/sh -c make build]: exit code: 2
看到无论是shell脚本还是docker部署时, 实际上cron以及consumer都没有启动;
另外, 使用eagle new xxx
安装脚手架后, config文件夹下应该像这个repo里分为docker和local的配置文件, 而不是把local配置文件直接放到config文件夹下;
lizhou@DESKTOP-Q8VGRRH:~/projects/eagle$ ./eagle
2021/11/27 16:24:47 maxprocs: Leaving GOMAXPROCS=12: CPU quota undefined
2021/11/27 16:24:47 /home/lizhou/projects/eagle/pkg/storage/orm/orm.go:54
[error] failed to initialize database, got error Error 1045: Unknown error 1045
2021/11/27 16:24:47 database connection failed. database name: eagle, err: Error 1045: Unknown error 1045
panic: database connection failed. database name: eagle, err: Error 1045: Unknown error 1045
goroutine 1 [running]:
log.Panicf({0x101f05c, 0x5}, {0xc00065dcb8, 0x4e, 0x6})
/usr/local/go/src/log/log.go:361 +0x67
github.com/go-eagle/eagle/pkg/storage/orm.NewMySQL(0xc0005bc620)
/home/lizhou/projects/eagle/pkg/storage/orm/orm.go:56 +0x3a5
github.com/go-eagle/eagle/internal/model.Init()
/home/lizhou/projects/eagle/internal/model/init.go:22 +0x2a
main.main()
/home/lizhou/projects/eagle/main.go:74 +0x311
系统
Linux DESKTOP-Q8VGRRH 5.10.16.3-microsoft-standard-WSL2 #1 SMP Fri Apr 2 22:23:49 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
这个脚手架太好用了,一键创建完项目基本上只用写业务逻辑就行了,如果只想生成一个只有http server 的项目模板没有grpc的模板该怎么做,现在好像默认grpc server 是必须的,能否做成可配置的或者生成项目模板的时候选择只生成 http server 不要grpc server
transport下的http.Server中的timeout没有跟标准包中的http.Server的ReadTimeout,WriteTimeout结合起来
https://github.com/1024casts/snake/blob/9c75dc4e686c308ad739aa1229acafeaff03ba3d/config/config.yaml#L16
应该是先 cd
到 conf
...
cd conf
# 生成本地环境配置文件
cp config.sample.yaml config.local.yaml
cd ..
微信交流群二维码已过期
脚手架现在支持redis,有完善RabbitMQ或Kafak的计划吗
请问前端目录放哪里好了,如果用nginx放静态资源使用哪个目录呢
2021/11/28 14:01:51 maxprocs: Leaving GOMAXPROCS=12: CPU quota undefined
app yaml
panic: config file not found
goroutine 1 [running]:
main.main()
/go/src/github.com/go-eagle/eagle/main.go:66 +0x7fa
internal/dao/user_base_dao_test.go:36
不知道是作者有意而为之,还是笔误
如题
runtime error: invalid memory address or nil pointer dereference
D:/Program Files/Go/src/runtime/panic.go:221 (0xeaa704)
panicmem: panic(memoryError)
D:/Program Files/Go/src/runtime/signal_windows.go:254 (0xec14f0)
sigpanic: panicmem()
d:/projects/eagle/web/response.go:51 (0x1d506d2)
SetLoginCookie: session.Options = &sessions.Options{
d:/projects/eagle/web/user/login.go:55 (0x1d51744)
DoLogin: web.SetLoginCookie(c, d.ID)
C:/Users/Administrator/go/pkg/mod/github.com/gin-gonic/[email protected]/context.go:165 (0x15e451c)
(*Context).Next: c.handlers[c.index](c)
d:/projects/eagle/internal/middleware/translations.go:37 (0x1d1bcb5)
Translations.func1: c.Next()
C:/Users/Administrator/go/pkg/mod/github.com/gin-gonic/[email protected]/context.go:165 (0x15e451c)
(*Context).Next: c.handlers[c.index](c)
d:/projects/eagle/pkg/middleware/timeout.go:34 (0x1d40b84)
Timeout.func1: c.Next()
C:/Users/Administrator/go/pkg/mod/github.com/gin-gonic/[email protected]/context.go:165 (0x15e451c)
(*Context).Next: c.handlers[c.index](c)
d:/projects/eagle/pkg/middleware/tracing.go:91 (0x1d418f5)
Tracing.func1: c.Next()
C:/Users/Administrator/go/pkg/mod/github.com/gin-gonic/[email protected]/context.go:165 (0x15e451c)
(*Context).Next: c.handlers[c.index](c)
d:/projects/eagle/pkg/middleware/metrics.go:93 (0x1d3ffd2)
Metrics.func1: c.Next()
C:/Users/Administrator/go/pkg/mod/github.com/gin-gonic/[email protected]/context.go:165 (0x15e451c)
(*Context).Next: c.handlers[c.index](c)
d:/projects/eagle/pkg/middleware/requestid.go:33 (0x1d4292e)
RequestID.func1: c.Next()
C:/Users/Administrator/go/pkg/mod/github.com/gin-gonic/[email protected]/context.go:165 (0x15e451c)
(*Context).Next: c.handlers[c.index](c)
d:/projects/eagle/pkg/middleware/logging.go:60 (0x1d42213)
Logging.func1: c.Next()
C:/Users/Administrator/go/pkg/mod/github.com/gin-gonic/[email protected]/context.go:165 (0x15e451c)
(*Context).Next: c.handlers[c.index](c)
d:/projects/eagle/pkg/middleware/header.go:24 (0x1d3f7ac)
Options: c.Next()
C:/Users/Administrator/go/pkg/mod/github.com/gin-gonic/[email protected]/context.go:165 (0x15e451c)
(*Context).Next: c.handlers[c.index](c)
d:/projects/eagle/pkg/middleware/header.go:16 (0x1d3f62e)
NoCache: c.Next()
C:/Users/Administrator/go/pkg/mod/github.com/gin-gonic/[email protected]/context.go:165 (0x15e451c)
(*Context).Next: c.handlers[c.index](c)
C:/Users/Administrator/go/pkg/mod/github.com/gin-gonic/[email protected]/recovery.go:99 (0x15f4b04)
CustomRecoveryWithWriter.func1: c.Next()
C:/Users/Administrator/go/pkg/mod/github.com/gin-gonic/[email protected]/context.go:165 (0x15e451c)
(*Context).Next: c.handlers[c.index](c)
C:/Users/Administrator/go/pkg/mod/github.com/gin-gonic/[email protected]/gin.go:489 (0x15f2913)
(*Engine).handleHTTPRequest: c.Next()
C:/Users/Administrator/go/pkg/mod/github.com/gin-gonic/[email protected]/gin.go:445 (0x15f241a)
(*Engine).ServeHTTP: engine.handleHTTPRequest(c)
D:/Program Files/Go/src/net/http/server.go:2878 (0x12a16f9)
serverHandler.ServeHTTP: handler.ServeHTTP(rw, req)
D:/Program Files/Go/src/net/http/server.go:1929 (0x129b1b7)
(*conn).serve: serverHandler{c.server}.ServeHTTP(w, w.req)
D:/Program Files/Go/src/runtime/asm_amd64.s:1581 (0xedeca0)
goexit: BYTE $0x90 // NOP
没看懂这里分页的逻辑
func FollowList(c *gin.Context) {
// get the underlying request context
ctx := c.Request.Context()
// create a done channel to tell the request it's done
doneChan := make(chan ListResponse)
// create a err channel
errChan := make(chan error)
// here you put the actual work needed for the request
// and then send the doneChan with the status and body
// to finish the request by writing the response
go func() {
userIDStr := c.Param("id")
userID, _ := strconv.Atoi(userIDStr)
curUserID := service.GetUserID(c)
log.Infof("cur uid: %d", curUserID)
_, err := service.Svc.Users().GetUserByID(ctx, uint64(userID))
if err != nil {
errChan <- ecode.ErrUserNotFound
return
}
lastIDStr := c.DefaultQuery("last_id", "0")
lastID, _ := strconv.Atoi(lastIDStr)
limit := 10
userFollowList, err := service.Svc.Relations().GetFollowingUserList(ctx, uint64(userID), uint64(lastID), limit+1)
if err != nil {
log.Warnf("get following user list err: %+v", err)
errChan <- errcode.ErrInternalServer
return
}
hasMore := 0
pageValue := lastID
if len(userFollowList) > limit {
hasMore = 1
userFollowList = userFollowList[0 : len(userFollowList)-1]
pageValue = lastID + 1
}
var userIDs []uint64
for _, v := range userFollowList {
userIDs = append(userIDs, v.FollowedUID)
}
userOutList, err := service.Svc.Users().BatchGetUsers(ctx, curUserID, userIDs)
if err != nil {
log.Warnf("batch get users err: %v", err)
errChan <- errcode.ErrInternalServer
return
}
doneChan <- ListResponse{
TotalCount: 0,
HasMore: hasMore,
PageKey: "last_id",
PageValue: pageValue,
Items: userOutList,
}
}()
// non-blocking select on two channels see if the request
// times out or finishes
select {
// if the context is done it timed out or was canceled
// so don't return anything
case <-ctx.Done():
return
// if err is not nil return error response
case err := <-errChan:
response.Error(c, err)
// if the request finished then finish the request by
// writing the response
case resp := <-doneChan:
response.Success(c, resp)
}
}
middleware.Auth()函数缺少参数,我刚刚clone这个项目,看到修改是两天前,请问下这是的传参应该是什么呀
可以集成常用MQ队列组件如:amqp,redis等。
一个登录接口,在响应中我需要设置一个header, token用来给用户后续验证登录信息。
我尝试使用了gin的中间件,在router文件中加入了
g.Use(setHttpResponseWriter())
func setHttpResponseWriter() gin.HandlerFunc {
return func(c *gin.Context) {
ctx := c.Request.Context()
// 将 HTTP 请求和响应存储到 gRPC 上下文中
ctx = context.WithValue(ctx, "writer", c.Writer)
c.Request = c.Request.WithContext(ctx)
c.Next()
}
}
c, ok := ctx.Value("writer").(gin.ResponseWriter)
但是这种方式无法获取到我设置在ctx中的gin.ResponseWriter 请教该如何处理呢?
go 版本1.16.4
系统 windows
make build 后:
D:\web\goiot\eagle>make build
FIND: 参数格式不正确
github.com/go-eagle/eagle/pkg/utils
# github.com/go-eagle/eagle/pkg/utils
pkg\utils\string.go:75:20: undefined: unsafe
pkg\utils\string.go:80:23: undefined: unsafe
pkg\utils\string.go:82:22: undefined: unsafe
make: *** [Makefile:30: build] Error 2
注释掉unsafe中的函数就正常了,请问注释掉影响大吗
RT
log:
log_format_text: true # 日志的输出格式,json或者plaintext,true会输出成plaintext格式,false会输出成json格式
plaintext 没有生效,看代码也只有 JSON 的 NewJSONEncoder
Describe the bug
A clear and concise description of what the bug is.
这个包不能用,本身有问题。你测试下看看,运行不起来。
--- FAIL: TestHttp (0.00s)
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x48 pc=0x1339e7d]
1.16
To Reproduce
Steps to reproduce the behavior:
Expected behavior
A clear and concise description of what you expected to happen.
Screenshots
If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
Smartphone (please complete the following information):
Additional context
Add any other context about the problem here.
TemplateEngine render read name:error/404, path:D:\goworkspace\src\gin-project\internal\templates\error\404.html, error: open D:\goworkspace\src\gin-project\internal\templates\error\404.html: The system cannot find the path specified
你好,我看之前的代码提交记录,在最初 log.Logger 是支持 Debug 级别的日志记录的,后来在 chore: optimize log 这次提交中去掉了 Debug 级别的支持。
我理解 Debug 级别的日志和 Info 级别的日志差别还是比较大的。在实践经验中,通常是开发和测试环境中开启 Debug 级别的日志,生产环境中开启 Info 日志,缺少 Debug 级别的日志会对测试环境排查问题有比较大的影响。
想了解下咱们是出于什么原因选择了这样的设计,以及后续是否有计划重新增加对 Debug 级别日志的支持呢?
RT,提个建议
Describe the bug
$ go mod tidy
go: github.com/go-eagle/[email protected] requires
github.com/mattn/[email protected]+incompatible: reading github.com/mattn/go-sqlite3/go.mod at revision v2.0.1: unknown revision v2.0.1
Sqlite3 documentation states that
Latest stable version is v1.14 or later, not v2.
And also there is no such version as v2.0.1 on github
(新手轻拍)
看了您的代码,pkg/cache封装了memory和redis,对外提供driver,然后在internal的cache包中针对不同业务使用cache,那么我看到internal/service/vcode中,要把验证码存放到缓存中,直接调用了pkg/redis中的client,为什么不通过封装好的cache接口来调用
当执行make build时候出现错误
internal/routers/router.go:13:2: no required module provides package github.com/go-eagle/eagle/docs; to add it:
Describe the bug
invalid argument "eagle:github.com/go-eagle/eagle/pkg/version" for "-t, --tag" flag: invalid reference format
To Reproduce
Steps to reproduce the behavior:
➜ eagle git:(master) ✗ make docker
docker build -t eagle:"github.com/go-eagle/eagle/pkg/version" -f Dockeffile .
invalid argument "eagle:github.com/go-eagle/eagle/pkg/version" for "-t, --tag" flag: invalid reference format
See 'docker build --help'.
make: *** [docker] Error 125
➜ eagle git:(master) ✗
Expected behavior
build success
Screenshots
If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
Smartphone (please complete the following information):
Additional context
Add any other context about the problem here.
cmd.zip
上面是我的cmd目录下的文件
在server目录中,执行wire ./... 生成wire_gen.go报错提示
wire: /Users/liangjiaming/code/eagle-demo/cmd/server/wire.go:16:1: inject InitApp: no provider found for *github.com/go-eagle/eagle/pkg/transport/consumer/redis.Server
needed by *github.com/go-eagle/eagle/pkg/app.App in provider "newApp" (/Users/liangjiaming/code/eagle-demo/cmd/server/main.go:100:6)
wire: eagle-demo/cmd/server: generate failed
wire: at least one generate failure
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.