Kratos是bilibili开源的一套Go微服务框架,包含大量微服务相关框架及工具。
名字来源于:《战神》游戏以希腊神话为背景,讲述由凡人成为战神的奎托斯(Kratos)成为战神并展开弑神屠杀的冒险历程。
我们致力于提供完整的微服务研发体验,整合相关框架及工具后,微服务治理相关部分可对整体业务开发周期无感,从而更加聚焦于业务交付。对每位开发者而言,整套Kratos框架也是不错的学习仓库,可以了解和参考到bilibili在微服务方面的技术积累和经验。
HTTP Blademaster
:核心基于gin进行模块化设计,简单易用、核心足够轻量;GRPC Warden
:基于官方gRPC开发,集成discovery服务发现,并融合P2C负载均衡;Cache
:优雅的接口化设计,非常方便的缓存序列化,推荐结合代理模式overlord;Database
:集成MySQL/HBase/TiDB,添加熔断保护和统计支持,可快速发现数据层压力;Config
:方便易用的paladin sdk,可配合远程配置中心,实现配置版本管理和更新;Log
:类似zap的field实现高性能日志库,并结合log-agent实现远程日志管理;Trace
:基于opentracing,集成了全链路trace支持(gRPC/HTTP/MySQL/Redis/Memcached);Kratos Tool
:工具链,可快速生成标准项目,或者通过Protobuf生成代码,非常便捷使用gRPC、HTTP、swagger文档
Go version>=1.13
GO111MODULE=on && go get -u github.com/go-kratos/kratos/tool/kratos
cd $GOPATH/src
kratos new kratos-demo
通过kratos new
会快速生成基于kratos库的脚手架代码,如生成 kratos-demo
cd kratos-demo/cmd
go build
./cmd -conf ../configs
打开浏览器访问:http://localhost:8000/kratos-demo/start,你会看到输出了Golang 大法好 !!!
以上是官网介绍,有点简单,安装过程中会出现很多问题。
特别注意:如果不是MacOS系统,需要自己进行手动安装protoc,用于生成的示例项目api目录下的proto文件并不会自动生成对应的.pb.go
和.bm.go
文件。
如果生成项目的时候并未使用--proto
,则可以使用命令:
// generate all
kratos tool protoc api.proto
// generate gRPC
kratos tool protoc --grpc api.proto
// generate BM HTTP
kratos tool protoc --bm api.proto
// generate swagger
kratos tool protoc --swagger api.proto
对应生成 api.pb.go/api.bm.go/api.swagger.json
源文档。
下载地址:https://github.com/google/protobuf/releases
1)、Linux系统(这里使用的是Ubuntu18.04)
下载后解压如下
进入到解压后的文件夹,执行如下命令:
sudo mv include/google /usr/local/include/
kratos@kratos:~/protoc-3.11.2-linux-x86_64$ sudo mv include/google /usr/local/include/
[sudo] kratos 的密码:
2)、Windows系统(这里使用的是win10)
下载后解压如下
把该文件夹放到你想要放的地方,然后在系统(或者用户)中添加bin目录环境变量,例:D:\goproject\protoc-3.11.2-win64\bin
以下设置是临时修改PATH,下面有永久修改的方法,只需在文件最后把设置代理的命令添加进去即可。在任意路径下打开终端输出命令即可。只在当前命令窗口管用,若新开命令窗口,还要重新执行以下两条命令。也可以直接在系统中设置,Linux(自行网上搜索怎么设置)
1)、打开 go111module
export GO111MODULE=on
2)、默认代理是
GOPROXY="https://proxy.golang.org,direct"
以下代理建议用第一个
1、
export GOPROXY=https://goproxy.cn/
2、export GOPROXY=https://goproxy.io/
3、export GOPROXY=https://mirrors.aliyun.com/goproxy/
4、export GOPROXY=https://athens.azurefd.net
3)、使用go env
查看
linux下永久修改环境变量PATH的三种方式
只需把以上两条命令添加到文件最后即可,以下三种方法只是示例
方法一:.bashrc
修改
1、进入当前用户的.bashrc文件:
vim ~/.bashrc
2、在.bashrc的最后一行添加相应的路径:
export PATH=/usr/local/bin:$PATH
3.使环境变量生效:
source ~/.bashrc
或者
. ~/.bashrc
注意:此种方法仅仅对当前用户有效
方法二:profile
修改
1、进入系统的profile文件:
vim /etc/profile
2、找到设置PATH的行(不一定是最后一行),然后添加:
export PATH=/usr/local/bin:$PATH
3、重启linux系统
注意:此种方法对所有用户有效
方法三:environment
修改
1、进入系统的environment文件:
vim /etc/environment
2、直接在PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin"加入相应路径即可:
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
3、重启linux系统
注意:此种方法对所有用户有效
1、 临时设置:
1)、打开 go111module
set GO111MODULE=on
2)、默认代理是
GOPROXY="https://proxy.golang.org,direct"
以下代理建议用第一个
1、
set GOPROXY=https://goproxy.cn/
2、set GOPROXY=https://goproxy.io/
3、set GOPROXY=https://mirrors.aliyun.com/goproxy/
4、set GOPROXY=https://athens.azurefd.net
2、永久设置:
只需在环境变量中添加进去即可(这里是在系统环境变量中进行设置)
go get -u github.com/golang/protobuf/proto
kratos@kratos:~$ go get -u github.com/golang/protobuf/proto
go: finding github.com/golang/protobuf v1.3.2
go: downloading github.com/golang/protobuf v1.3.2
go: extracting github.com/golang/protobuf v1.3.2
go get github.com/golang/protobuf/protoc-gen-go
kratos@kratos:~$ go get github.com/golang/protobuf/protoc-gen-go
kratos@kratos:~$
//gogo
go get github.com/gogo/protobuf/protoc-gen-gogo
kratos@kratos:~$ go get github.com/gogo/protobuf/protoc-gen-gogo
go: finding github.com/gogo/protobuf v1.3.1
go: downloading github.com/gogo/protobuf v1.3.1
go: extracting github.com/gogo/protobuf v1.3.1
//gofast
go get github.com/gogo/protobuf/protoc-gen-gofast
kratos@kratos:~$ go get github.com/gogo/protobuf/protoc-gen-gofast
kratos@kratos:~$
//依赖
go get github.com/gogo/protobuf/proto
go get github.com/gogo/protobuf/gogoproto
kratos@kratos:~$ go get github.com/gogo/protobuf/proto
kratos@kratos:~$ go get github.com/gogo/protobuf/gogoproto
kratos@kratos:~$
// grpc (或者git clone https://github.com/grpc/grpc-go 然后复制到google.golang.org/grpc)
go get -u google.golang.org/grpc
kratos@kratos:~$ go get -u google.golang.org/grpc
go: finding google.golang.org/grpc v1.26.0
go: downloading google.golang.org/grpc v1.26.0
go: extracting google.golang.org/grpc v1.26.0
go: downloading golang.org/x/net v0.0.0-20190311183353-d8887717615a
go: downloading google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55
go: downloading golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a
go: extracting golang.org/x/net v0.0.0-20190311183353-d8887717615a
go: downloading golang.org/x/text v0.3.0
go: extracting golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a
go: extracting google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55
go: extracting golang.org/x/text v0.3.0
go: finding golang.org/x/sys latest
go: finding golang.org/x/net latest
go: finding google.golang.org/genproto latest
go: finding golang.org/x/text v0.3.2
go: downloading golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553
go: downloading golang.org/x/sys v0.0.0-20200106162015-b016eb3dc98e
go: downloading google.golang.org/genproto v0.0.0-20191230161307-f3c370f40bfb
go: extracting golang.org/x/sys v0.0.0-20200106162015-b016eb3dc98e
go: extracting golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553
go: downloading golang.org/x/text v0.3.2
go: extracting google.golang.org/genproto v0.0.0-20191230161307-f3c370f40bfb
go: extracting golang.org/x/text v0.3.2
// genproto (或者git clone https://github.com/google/go-genproto 然后复制到google.golang.org/genproto)
go get google.golang.org/genproto/...
kratos@kratos:~$ go get google.golang.org/genproto/...
go: finding google.golang.org/genproto latest
go: downloading google.golang.org/grpc v1.19.0
go: downloading honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099
go: downloading golang.org/x/tools v0.0.0-20190226205152-f727befe758c
go: downloading golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961
go: downloading golang.org/x/exp v0.0.0-20190121172915-509febef88a4
go: extracting golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961
go: extracting honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099
go: extracting google.golang.org/grpc v1.19.0
go: downloading golang.org/x/net v0.0.0-20190213061140-3a22650c66bd
go: downloading github.com/BurntSushi/toml v0.3.1
go: downloading golang.org/x/sys v0.0.0-20180830151530-49385e6e1522
go: extracting golang.org/x/exp v0.0.0-20190121172915-509febef88a4
go: extracting github.com/BurntSushi/toml v0.3.1
go: extracting golang.org/x/tools v0.0.0-20190226205152-f727befe758c
go: extracting golang.org/x/sys v0.0.0-20180830151530-49385e6e1522
go: extracting golang.org/x/net v0.0.0-20190213061140-3a22650c66bd
go: finding google.golang.org/grpc v1.19.0
go: finding golang.org/x/net v0.0.0-20190213061140-3a22650c66bd
go: finding golang.org/x/sys v0.0.0-20180830151530-49385e6e1522
go: finding golang.org/x/text v0.3.0
go get -u github.com/bilibili/kratos/tool/kratos
已更新为
go get -u github.com/go-kratos/kratos/tool/kratos
kratos@kratos:~$ go get -u github.com/bilibili/kratos/tool/kratos
go: finding github.com/bilibili/kratos v0.3.1
go: downloading github.com/bilibili/kratos v0.3.1
go: extracting github.com/bilibili/kratos v0.3.1
go: downloading github.com/urfave/cli v1.22.1
go: downloading github.com/fatih/color v1.7.0
go: extracting github.com/fatih/color v1.7.0
go: downloading github.com/mattn/go-isatty v0.0.10
go: downloading github.com/mattn/go-colorable v0.1.4
go: extracting github.com/urfave/cli v1.22.1
go: downloading github.com/cpuguy83/go-md2man v1.0.10
go: extracting github.com/mattn/go-colorable v0.1.4
go: extracting github.com/cpuguy83/go-md2man v1.0.10
go: extracting github.com/mattn/go-isatty v0.0.10
go: downloading github.com/cpuguy83/go-md2man/v2 v2.0.0
go: downloading golang.org/x/sys v0.0.0-20191105231009-c1f44814a5cd
go: extracting github.com/cpuguy83/go-md2man/v2 v2.0.0
go: downloading github.com/russross/blackfriday v1.5.2
go: extracting golang.org/x/sys v0.0.0-20191105231009-c1f44814a5cd
go: extracting github.com/russross/blackfriday v1.5.2
go: downloading github.com/russross/blackfriday/v2 v2.0.1
go: extracting github.com/russross/blackfriday/v2 v2.0.1
go: downloading github.com/shurcooL/sanitized_anchor_name v1.0.0
go: extracting github.com/shurcooL/sanitized_anchor_name v1.0.0
go: finding golang.org/x/sys latest
go: finding github.com/fatih/color v1.8.0
go: finding github.com/mattn/go-isatty v0.0.11
go: finding github.com/urfave/cli v1.22.2
go: finding github.com/cpuguy83/go-md2man/v2 v2.0.0
go: finding github.com/shurcooL/sanitized_anchor_name v1.0.0
go: finding github.com/mattn/go-colorable v0.1.4
go: finding github.com/russross/blackfriday/v2 v2.0.1
go: downloading github.com/urfave/cli v1.22.2
go: downloading github.com/fatih/color v1.8.0
go: extracting github.com/fatih/color v1.8.0
go: downloading github.com/mattn/go-isatty v0.0.11
go: extracting github.com/mattn/go-isatty v0.0.11
go: extracting github.com/urfave/cli v1.22.2
若GOPATH目录下没有src目录,则创建src目录
1)、Linux
进入到之前解压后的文件夹,执行如下命令:
mv bin/protoc /usr/local/bin/
kratos@kratos:~/protoc-3.11.2-linux-x86_64$ sudo mv bin/protoc /usr/local/bin/
[sudo] kratos 的密码:
cd $GOPATH/src
kratos new kratos-demo
或者kratos new kratos-demo --proto
2)、Windows 这里是在系统环境变量中进行设置
(D:\goproject,这是我的Windows中的GOPATH目录)。以上步骤走完,会在D:\goproject目录下生成bin和pkg目录,如下图所示:
添加bin目录环境变量。例:D:\goproject\bin
kratos new是快速创建一个项目的命令,执行如下:
kratos new kratos-demo
即可快速在当前目录生成一个叫kratos-demo的项目。此外还支持指定owner和path,如下:
kratos new kratos-demo -o YourName -d YourPath
注意,kratos new
默认是不会生成通过 protobuf 定义的grpc和bm示例代码的,如需生成请加–proto,如下:
kratos new kratos-demo -o YourName -d YourPath --proto
如只生成bm请加–http,如下:
kratos new kratos-demo -o YourName -d YourPath --http
如只生成grpc请加–grpc,如下:
kratos new kratos-demo -o YourName -d YourPath --grpc
通过 kratos new
会快速生成基于kratos库的脚手架代码,如生成 kratos-demo
kratos@kratos:~/go/src$ kratos new kratos-demo --proto
go get -u github.com/bilibili/kratos/tool/kratos-gen-project
go: downloading github.com/gobuffalo/packr/v2 v2.7.1
go: extracting github.com/gobuffalo/packr/v2 v2.7.1
go: downloading github.com/gobuffalo/envy v1.7.1
go: downloading github.com/sirupsen/logrus v1.4.2
go: downloading github.com/gobuffalo/packd v0.3.0
go: downloading github.com/gobuffalo/logger v1.0.1
go: extracting github.com/gobuffalo/logger v1.0.1
go: extracting github.com/gobuffalo/packd v0.3.0
go: downloading golang.org/x/crypto v0.0.0-20191105034135-c7e5f84aec59
go: extracting github.com/sirupsen/logrus v1.4.2
go: downloading github.com/konsorten/go-windows-terminal-sequences v1.0.2
go: extracting github.com/gobuffalo/envy v1.7.1
go: downloading github.com/joho/godotenv v1.3.0
go: downloading github.com/rogpeppe/go-internal v1.5.0
go: extracting github.com/konsorten/go-windows-terminal-sequences v1.0.2
go: extracting github.com/joho/godotenv v1.3.0
go: extracting github.com/rogpeppe/go-internal v1.5.0
go: extracting golang.org/x/crypto v0.0.0-20191105034135-c7e5f84aec59
go: finding golang.org/x/crypto latest
go: finding github.com/gobuffalo/packd v0.3.0
go: finding golang.org/x/sys latest
go: finding github.com/konsorten/go-windows-terminal-sequences v1.0.2
go: finding github.com/rogpeppe/go-internal v1.5.1
go: finding github.com/sirupsen/logrus v1.4.2
go: finding github.com/gobuffalo/logger v1.0.3
go: finding github.com/joho/godotenv v1.3.0
go: finding github.com/gobuffalo/envy v1.8.1
go: finding github.com/gobuffalo/packr/v2 v2.7.1
go: downloading github.com/gobuffalo/logger v1.0.3
go: downloading github.com/gobuffalo/envy v1.8.1
go: extracting github.com/gobuffalo/logger v1.0.3
go: extracting github.com/gobuffalo/envy v1.8.1
go: downloading golang.org/x/crypto v0.0.0-20191227163750-53104e6ec876
go: downloading github.com/rogpeppe/go-internal v1.5.1
go: extracting github.com/rogpeppe/go-internal v1.5.1
go: extracting golang.org/x/crypto v0.0.0-20191227163750-53104e6ec876
genproject: 安装成功!
go: finding github.com/bilibili/kratos master
go: downloading github.com/bilibili/kratos v0.3.2-0.20191224125553-6e1180f53a8e
go: downloading google.golang.org/grpc v1.24.0
go: extracting google.golang.org/grpc v1.24.0
go: extracting github.com/bilibili/kratos v0.3.2-0.20191224125553-6e1180f53a8e
go: downloading golang.org/x/net v0.0.0-20191011234655-491137f69257
go: downloading github.com/fsnotify/fsnotify v1.4.7
go: downloading gopkg.in/go-playground/validator.v9 v9.29.1
go: downloading google.golang.org/genproto v0.0.0-20191216205247-b31c10ee225f
go: downloading github.com/gogo/protobuf v1.3.0
go: downloading github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2
go: downloading github.com/prometheus/client_golang v1.1.0
go: extracting github.com/fsnotify/fsnotify v1.4.7
go: downloading github.com/go-sql-driver/mysql v1.4.1
go: extracting golang.org/x/net v0.0.0-20191011234655-491137f69257
go: extracting gopkg.in/go-playground/validator.v9 v9.29.1
go: downloading github.com/go-playground/universal-translator v0.16.0
go: extracting github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2
go: downloading github.com/leodido/go-urn v1.1.0
go: downloading gopkg.in/yaml.v2 v2.2.2
go: extracting github.com/prometheus/client_golang v1.1.0
go: downloading github.com/pkg/errors v0.8.1
go: downloading github.com/prometheus/common v0.6.0
go: extracting github.com/pkg/errors v0.8.1
go: extracting github.com/leodido/go-urn v1.1.0
go: downloading github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90
go: extracting github.com/go-playground/universal-translator v0.16.0
go: extracting github.com/go-sql-driver/mysql v1.4.1
go: extracting gopkg.in/yaml.v2 v2.2.2
go: extracting github.com/prometheus/common v0.6.0
go: downloading github.com/beorn7/perks v1.0.1
go: downloading github.com/shirou/gopsutil v2.19.6+incompatible
go: downloading github.com/go-playground/locales v0.12.1
go: downloading github.com/matttproud/golang_protobuf_extensions v1.0.1
go: downloading github.com/prometheus/procfs v0.0.3
go: extracting github.com/gogo/protobuf v1.3.0
go: extracting github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90
go: extracting github.com/prometheus/procfs v0.0.3
go: extracting github.com/beorn7/perks v1.0.1
go: extracting github.com/matttproud/golang_protobuf_extensions v1.0.1
go: extracting github.com/shirou/gopsutil v2.19.6+incompatible
go: extracting google.golang.org/genproto v0.0.0-20191216205247-b31c10ee225f
go: extracting github.com/go-playground/locales v0.12.1
go get -u github.com/bilibili/kratos/tool/kratos-protoc
protoc: 安装成功!
2020/01/07 14:32:34 go get -u github.com/bilibili/kratos/tool/protobuf/protoc-gen-bm
go: downloading github.com/siddontang/go v0.0.0-20180604090527-bdc77568d726
go: extracting github.com/siddontang/go v0.0.0-20180604090527-bdc77568d726
go: finding github.com/pkg/errors v0.8.1
go: finding google.golang.org/genproto latest
go: finding github.com/siddontang/go latest
2020/01/07 14:32:37 protoc --proto_path=/home/kratos/go/src --proto_path=/home/kratos/go/pkg/mod/github.com/bilibili/kratos@v0.3.2-0.20191224125553-6e1180f53a8e/third_party --proto_path=/home/kratos/go/src/kratos-demo/api --bm_out=:. api.proto
2020/01/07 14:32:37 protoc --proto_path=/home/kratos/go/src --proto_path=/home/kratos/go/pkg/mod/github.com/bilibili/kratos@v0.3.2-0.20191224125553-6e1180f53a8e/third_party --proto_path=/home/bqpbqt/go/src/kratos-demo/api --gofast_out=plugins=grpc:. api.proto
2020/01/07 14:32:37 generate api.proto success.
go get -u github.com/bilibili/kratos/tool/kratos-gen-bts
genbts: 安装成功!
Close: 无声明 忽略此方法
Ping: 无声明 忽略此方法
dao.bts.go: 生成成功
go get -u github.com/bilibili/kratos/tool/kratos-gen-mc
genmc: 安装成功!
mc.cache.go: 生成成功
go get -u github.com/google/wire/cmd/wire
go: finding github.com/google/wire v0.4.0
go: downloading github.com/google/wire v0.4.0
go: extracting github.com/google/wire v0.4.0
go: downloading github.com/google/subcommands v1.0.1
go: downloading golang.org/x/tools v0.0.0-20190422233926-fe54fb35175b
go: downloading github.com/pmezard/go-difflib v1.0.0
go: extracting github.com/google/subcommands v1.0.1
go: extracting github.com/pmezard/go-difflib v1.0.0
go: extracting golang.org/x/tools v0.0.0-20190422233926-fe54fb35175b
go: finding golang.org/x/tools latest
go: finding github.com/google/subcommands v1.0.1
go: finding github.com/pmezard/go-difflib v1.0.0
go: downloading golang.org/x/tools v0.0.0-20200107050322-53017a39ae36
go: extracting golang.org/x/tools v0.0.0-20200107050322-53017a39ae36
wire: 安装成功!
wire: go [list -e -json -compiled=true -test=false -export=false -deps=true -find=false -tags=wireinject -- .]: exit status 2: go: finding gopkg.in/go-playground/validator.v9 v9.29.1
go: finding github.com/gogo/protobuf v1.3.0
go: finding github.com/prometheus/client_golang v1.1.0
go: finding github.com/go-playground/universal-translator v0.16.0
go: finding github.com/BurntSushi/toml v0.3.1
go: finding google.golang.org/grpc v1.24.0
go: finding github.com/fsnotify/fsnotify v1.4.7
go: finding github.com/go-playground/locales v0.12.1
go: finding gopkg.in/yaml.v2 v2.2.2
go: finding github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2
go: finding github.com/leodido/go-urn v1.1.0
go: finding github.com/beorn7/perks v1.0.1
go: finding github.com/go-sql-driver/mysql v1.4.1
go: finding golang.org/x/sys v0.0.0-20191105231009-c1f44814a5cd
go: finding github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90
go: finding github.com/prometheus/common v0.6.0
go: finding golang.org/x/net v0.0.0-20191011234655-491137f69257
go: finding github.com/prometheus/procfs v0.0.3
go: finding github.com/shirou/gopsutil v2.19.6+incompatible
go: finding github.com/matttproud/golang_protobuf_extensions v1.0.1
# runtime/cgo
exec: "gcc": executable file not found in $PATH
wire: generate failed
exit status 1
Project: kratos-demo
OnlyGRPC: false
OnlyHTTP: false
Directory: /home/kratos/go/src/kratos-demo
项目创建成功.
可以看到有可能会出现wire: generate failed
,(为了确保protoc能够执行,删除kratos-demo
目录并重新创建)此时,把生成在src目录中的 kratos-demo
项目文件夹删掉,再重新执行以下命令生成kratos-demo
目录:
kratos new kratos-demo --proto
kratos@kratos:~/go/src$ kratos new kratos-demo --proto
go: finding github.com/bilibili/kratos master
2020/01/07 14:34:43 protoc --proto_path=/home/kratos/go/src --proto_path=/home/kratos/go/pkg/mod/github.com/bilibili/kratos@v0.3.2-0.20191224125553-6e1180f53a8e/third_party --proto_path=/home/kratos/go/src/kratos-demo/api --bm_out=:. api.proto
2020/01/07 14:34:43 protoc --proto_path=/home/kratos/go/src --proto_path=/home/kratos/go/pkg/mod/github.com/bilibili/kratos@v0.3.2-0.20191224125553-6e1180f53a8e/third_party --proto_path=/home/kratos/go/src/kratos-demo/api --gofast_out=plugins=grpc:. api.proto
2020/01/07 14:34:43 generate api.proto success.
Close: 无声明 忽略此方法
Ping: 无声明 忽略此方法
dao.bts.go: 生成成功
mc.cache.go: 生成成功
wire: kratos-demo/internal/di: wrote /home/kratos/go/src/kratos-demo/internal/di/wire_gen.go
Project: kratos-demo
OnlyGRPC: false
OnlyHTTP: false
Directory: /home/kratos/go/src/kratos-demo
项目创建成功.
使用如下命令运行项目
1、kratos run
方式执行
cd kratos-demo
kratos run
kratos@kratos:~/go/src/kratos-demo$ kratos run
INFO 01/07-14:51:27.953 /home/kratos/go/src/kratos-demo/cmd/main.go:19 abc start
2020/01/07 14:51:27 start watch filepath: /home/kratos/go/src/kratos-demo/configs
INFO 01/07-14:51:27.954 /home/kratos/go/pkg/mod/github.com/bilibili/kratos@v0.3.2-0.20191224125553-6e1180f53a8e/pkg/net/http/blademaster/server.go:98 blademaster: start http listen addr: 0.0.0.0:8000
[warden] config is Deprecated, argument will be ignored. please use -grpc flag or GRPC env to configure warden server.
INFO 01/07-14:51:27.954 /home/kratos/go/pkg/mod/github.com/bilibili/kratos@v0.3.2-0.20191224125553-6e1180f53a8e/pkg/net/rpc/warden/server.go:329 warden: start grpc listen addr: [::]:9000
2、go build
方式执行
cd kratos-demo/cmd
go build
./cmd -conf ../configs
kratos@kratos:~/go/src/kratos-demo$ cd cmd/
kratos@kratos:~/go/src/kratos-demo/cmd$ ls
main.go
kratos@kratos:~/go/src/kratos-demo/cmd$ go build
kratos@kratos:~/go/src/kratos-demo/cmd$ ls
cmd main.go
kratos@kratos:~/go/src/kratos-demo/cmd$ ./cmd -conf ../configs
INFO 01/07-15:00:46.302 /home/kratos/go/src/kratos-demo/cmd/main.go:19 abc start
INFO 01/07-15:00:46.302 /home/kratos/go/pkg/mod/github.com/bilibili/kratos@v0.3.2-0.20191224125553-6e1180f53a8e/pkg/net/http/blademaster/server.go:98 blademaster: start http listen addr: 0.0.0.0:8000
[warden] config is Deprecated, argument will be ignored. please use -grpc flag or GRPC env to configure warden server.
INFO 01/07-15:00:46.302 /home/kratos/go/pkg/mod/github.com/bilibili/kratos@v0.3.2-0.20191224125553-6e1180f53a8e/pkg/net/rpc/warden/server.go:329 warden: start grpc listen addr: [::]:9000
2020/01/07 15:00:46 start watch filepath: ../configs