项目无法启动
Opened this issue · 3 comments
Deleted user commented
你好,我将项目拉下来。运行:
make migrate
make setup
make swagger
make start
然后请求任何接口都会出现
github.com/RealLiuSha/echo-admin/api/middlewares.CoreMiddleware.core.func1.1.1(0xc001e757a0, 0xc00016c630, 0x1025c88, 0xc000372320)
/home/admin/Documents/projects/echo-admin/api/middlewares/core_middleware.go:59 +0xf0
panic(0xdd5260, 0x20dd6b0)
/usr/lib/go-1.16/src/runtime/panic.go:965 +0x1b9
github.com/RealLiuSha/echo-admin/api/middlewares.CasbinMiddleware.core.func1.1(0x1025c88, 0xc000372320, 0x0, 0x0)
/home/admin/Documents/projects/echo-admin/api/middlewares/casbin_middleware.go:53 +0x182
github.com/labstack/echo/v4/middleware.CORSWithConfig.func1.1(0x1025c88, 0xc000372320, 0x20f8a80, 0xc00076b900)
/home/admin/go/pkg/mod/github.com/labstack/echo/v4@v4.3.0/middleware/cors.go:118 +0x15a5
github.com/RealLiuSha/echo-admin/api/middlewares.ZapMiddleware.core.func1.1(0x1025c88, 0xc000372320, 0x6, 0xeca340)
/home/admin/Documents/projects/echo-admin/api/middlewares/zap_middleware.go:34 +0x8f
github.com/RealLiuSha/echo-admin/api/middlewares.CoreMiddleware.core.func1.1(0x1025c88, 0xc000372320, 0x0, 0x0)
/home/admin/Documents/projects/echo-admin/api/middlewares/core_middleware.go:72 +0x165
github.com/labstack/echo/v4.(*Echo).ServeHTTP(0xc001e60c00, 0x1013888, 0xc000798460, 0xc0002b6300)
/home/admin/go/pkg/mod/github.com/labstack/echo/v4@v4.3.0/echo.go:646 +0x2bc
net/http.serverHandler.ServeHTTP(0xc000446540, 0x1013888, 0xc000798460, 0xc0002b6300)
/usr/lib/go-1.16/src/net/http/server.go:2887 +0xa3
net/http.(*conn).serve(0xc0001ec280, 0x1015d80, 0xc000476140)
/usr/lib/go-1.16/src/net/http/server.go:1952 +0x8cd
created by net/http.(*Server).Serve
/usr/lib/go-1.16/src/net/http/server.go:3013 +0x39b
{"module": "core-mw"}
runtime.gopanic
/usr/lib/go-1.16/src/runtime/panic.go:965
runtime.panicmem
/usr/lib/go-1.16/src/runtime/panic.go:212
runtime.sigpanic
/usr/lib/go-1.16/src/runtime/signal_unix.go:734
github.com/RealLiuSha/echo-admin/api/middlewares.CasbinMiddleware.core.func1.1
/home/admin/Documents/projects/echo-admin/api/middlewares/casbin_middleware.go:53
github.com/labstack/echo/v4/middleware.CORSWithConfig.func1.1
/home/admin/go/pkg/mod/github.com/labstack/echo/v4@v4.3.0/middleware/cors.go:118
github.com/RealLiuSha/echo-admin/api/middlewares.ZapMiddleware.core.func1.1
/home/admin/Documents/projects/echo-admin/api/middlewares/zap_middleware.go:34
github.com/RealLiuSha/echo-admin/api/middlewares.CoreMiddleware.core.func1.1
/home/admin/Documents/projects/echo-admin/api/middlewares/core_middleware.go:72
github.com/labstack/echo/v4.(*Echo).ServeHTTP
/home/admin/go/pkg/mod/github.com/labstack/echo/v4@v4.3.0/echo.go:646
net/http.serverHandler.ServeHTTP
/usr/lib/go-1.16/src/net/http/server.go:2887
net/http.(*conn).serve
/usr/lib/go-1.16/src/net/http/server.go:1952
2021-05-18 22:02:22 INFO runtime/panic.go:965 rolling back transaction due to panic {"module": "core-mw"}
2021-05-18 22:02:22 INFO v4@v4.3.0/echo.go:646 beginning database transaction {"module": "core-mw"}
2021-05-18 22:02:22 ERROR runtime/panic.go:965 [PANIC RECOVER] runtime error: invalid memory address or nil pointer dereference goroutine 54 [running]:
github.com/RealLiuSha/echo-admin/api/middlewares.CoreMiddleware.core.func1.1.1(0xc001e757a0, 0xc000d5ad80, 0x1025c88, 0xc0003720a0)
/home/admin/Documents/projects/echo-admin/api/middlewares/core_middleware.go:59 +0xf0
panic(0xdd5260, 0x20dd6b0)
/usr/lib/go-1.16/src/runtime/panic.go:965 +0x1b9
github.com/RealLiuSha/echo-admin/api/middlewares.CasbinMiddleware.core.func1.1(0x1025c88, 0xc0003720a0, 0x0, 0x0)
/home/admin/Documents/projects/echo-admin/api/middlewares/casbin_middleware.go:53 +0x182
github.com/labstack/echo/v4/middleware.CORSWithConfig.func1.1(0x1025c88, 0xc0003720a0, 0x20f8a80, 0xc00076ac80)
/home/admin/go/pkg/mod/github.com/labstack/echo/v4@v4.3.0/middleware/cors.go:118 +0x15a5
github.com/RealLiuSha/echo-admin/api/middlewares.ZapMiddleware.core.func1.1(0x1025c88, 0xc0003720a0, 0x6, 0xeca340)
/home/admin/Documents/projects/echo-admin/api/middlewares/zap_middleware.go:34 +0x8f
github.com/RealLiuSha/echo-admin/api/middlewares.CoreMiddleware.core.func1.1(0x1025c88, 0xc0003720a0, 0x0, 0x0)
/home/admin/Documents/projects/echo-admin/api/middlewares/core_middleware.go:72 +0x165
github.com/labstack/echo/v4.(*Echo).ServeHTTP(0xc001e60c00, 0x1013888, 0xc000818700, 0xc0007ca500)
/home/admin/go/pkg/mod/github.com/labstack/echo/v4@v4.3.0/echo.go:646 +0x2bc
net/http.serverHandler.ServeHTTP(0xc000446540, 0x1013888, 0xc000818700, 0xc0007ca500)
/usr/lib/go-1.16/src/net/http/server.go:2887 +0xa3
net/http.(*conn).serve(0xc0001ec280, 0x1015d80, 0xc000476140)
/usr/lib/go-1.16/src/net/http/server.go:1952 +0x8cd
created by net/http.(*Server).Serve
/usr/lib/go-1.16/src/net/http/server.go:3013 +0x39b
{"module": "core-mw"}
runtime.gopanic
/usr/lib/go-1.16/src/runtime/panic.go:965
runtime.panicmem
/usr/lib/go-1.16/src/runtime/panic.go:212
runtime.sigpanic
/usr/lib/go-1.16/src/runtime/signal_unix.go:734
github.com/RealLiuSha/echo-admin/api/middlewares.CasbinMiddleware.core.func1.1
/home/admin/Documents/projects/echo-admin/api/middlewares/casbin_middleware.go:53
github.com/labstack/echo/v4/middleware.CORSWithConfig.func1.1
/home/admin/go/pkg/mod/github.com/labstack/echo/v4@v4.3.0/middleware/cors.go:118
github.com/RealLiuSha/echo-admin/api/middlewares.ZapMiddleware.core.func1.1
/home/admin/Documents/projects/echo-admin/api/middlewares/zap_middleware.go:34
github.com/RealLiuSha/echo-admin/api/middlewares.CoreMiddleware.core.func1.1
/home/admin/Documents/projects/echo-admin/api/middlewares/core_middleware.go:72
github.com/labstack/echo/v4.(*Echo).ServeHTTP
/home/admin/go/pkg/mod/github.com/labstack/echo/v4@v4.3.0/echo.go:646
net/http.serverHandler.ServeHTTP
/usr/lib/go-1.16/src/net/http/server.go:2887
net/http.(*conn).serve
/usr/lib/go-1.16/src/net/http/server.go:1952
2021-05-18 22:02:22 INFO runtime/panic.go:965 rolling back transaction due to panic {"module": "core-mw"}
^C2021-05-18 22:02:34 INFO lifecycle/lifecycle.go:86 Stopping Application
2021-05-18 22:02:34 DEBUG runtime/asm_amd64.s:1371 Shutting down the Application
make: *** [Makefile:16: start] Error 1
运行环境:
- Ubuntu 21.04
- Go 1.16.2
- MariaDB 10(Docker)
- Redis 6(Docker)
RealLiuSha commented
@kuzoncby
首先我们需要确认下基本的准备工作是否执行成功了, 比如
make migrate
make setup
如果建表塞数据都没问题, 我们可以试着请求下验证码的接口
curl 127.0.0.1:2222/api/v1/publics/captcha
我这边默认提供的配置文件关闭了接口的用户验证, 但是默认开启了 casbin, 因此你不做任何变更均会遇到这样的错误,原因如下:
auth mw 被关闭则不会 set current user, 此时由于 casbin 默认开启取不到当前用户,所以你无法运行该项目
我对 config.yaml.default 配置进行了调整, 也增加了 casbin 取 current user 判断, 你可以重新尝试一下
Deleted user commented
version: '3'
services:
mariadb:
image: "mariadb:10"
container_name: mariadb
hostname: mariadb
command: "--default-authentication-plugin=mysql_native_password,--default-storage-engine=MEMORY"
ports:
- 3306:3306
environment:
- MYSQL_DATABASE=echo
- MYSQL_USER=echo
- MYSQL_PASSWORD=echo
- MYSQL_ROOT_PASSWORD=echo
redis:
image: "redis:6"
container_name: redis
hostname: redis
ports:
- 6379:6379
换到 Mac 上,使用这个环境,然后修改好 config/config.yaml
(Redis 注释掉密码的那一行)运行:
make migrate
make setup
make start
就能启动了,可能是 Windows WSL 的 Ubuntu 并不是一个完整的系统,造成的问题。