Code Monkey home page Code Monkey logo

kratos-demo's Introduction

kratos-demo

项目简介

使用kratos框架的项目demo

生成

使用kratos工具工具生成

go get -u github.com/bilibili/kratos/tool/kratos	
cd $GOPATH/src	
kratos new kratos-demo

kratos-demo's People

Contributors

felixhao avatar terry-mao avatar xyuwang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

kratos-demo's Issues

lost client

you should commit client demo,so that is easy use it

初次接触搞不定了 ..undefined: DemoClient

`kratos tool protoc --grpc --bm api.proto
2020/04/15 17:33:32 protoc --proto_path=/Users/jelty/data/GoPath/src --proto_path=/Users/jelty/data/GoPath/pkg/mod/github.com/go-kratos/[email protected]/third_party --proto_path=/Users/jelty/data/GoPath/src/kratos-demo/api --bm_out=:. api.proto
api.proto: File does not reside within any path specified using --proto_path (or -I). You must specify a --proto_path which encompasses this file. Note that the proto_path must be an exact prefix of the .proto file names -- protoc is too dumb to figure out when two paths (e.g. absolute and relative) are equivalent (it's harder than you think).
exit status 1
exit status 1
kratos tool genbts
Close: 无声明 忽略此方法
Ping: 无声明 忽略此方法
dao.bts.go: 生成成功
kratos tool genmc
mc.cache.go: 生成成功
kratos tool wire
wire: /Users/jelty/data/GoPath/src/kratos-demo/internal/service/service.go:15:33: first argument to Bind must be a pointer to an interface type; found
wire: kratos-demo/internal/di: generate failed
wire: at least one generate failure
exit status 1
kratos tool wire
wire: kratos-demo/internal/dao: wrote /Users/jelty/data/GoPath/src/kratos-demo/internal/dao/wire_gen.go
Project: kratos-demo
OnlyGRPC: false
OnlyHTTP: false
Directory: /Users/jelty/data/GoPath/src/kratos-demo

项目创建成功.`

jelty@jeltydeMBP:~/data/GoPath/src/kratos-demo/cmd|
⇒ go build

kratos-demo/api

../api/client.go:15:68: undefined: DemoClient
../api/client.go:21:9: undefined: NewDemoClient

cmd下main loop下的defer是否放到闭包里会好一些

	for {
		s := <-c
		log.Info("get a signal %s", s.String())
		switch s {
		case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT:
			ctx, cancel := context.WithTimeout(context.Background(), 35*time.Second)
			defer cancel() //这里
			grpcSrv.Shutdown(ctx)
			httpSrv.Shutdown(ctx)
			log.Info("kratos-demo exit")
			svc.Close()
			time.Sleep(time.Second)
			return
		case syscall.SIGHUP:
		default:
			return
		}

改成

	for {
		s := <-c
		log.Info("get a signal %s", s.String())
		switch s {
		case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT:
			func(){
				ctx, cancel := context.WithTimeout(context.Background(), 35*time.Second)
				defer cancel()
				httpSrv.Shutdown(ctx)
				log.Info("kratos-demo exit")
				svc.Close()
				time.Sleep(time.Second)
			}()
			return
		case syscall.SIGHUP:
		default:
			return
		}
	}

这样idea就不会报warning了

Module path should be "github.com/bilibili/kratos-demo", not "kratos-demo"

Background

Module path is inconsistent with go import path.
GO111MODULE=on, run go get -u github.com/bilibili/kratos/tool/kratos:

go: downloading github.com/bilibili/kratos v0.5.0
go: found github.com/bilibili/kratos/tool/kratos in github.com/bilibili/kratos v0.5.0
go get: github.com/bilibili/[email protected]: parsing go.mod:
        module declares its path as: github.com/go-kratos/kratos
                but was required as: github.com/bilibili/kratos 

Solution

Fix the module path:

  1. Rename the module path to "github.com/bilibili/kratos": https://github.com/bilibili/kratos-demo/blob/master/go.mod#L1 :
module github.com/bilibili/kratos
go 1.13
require (
	…
) 
  1. Warning the users not to use the module, get "github.com/bilibili/kratos/tool/kratos " in GOPATH mode.

api/client.go:15:68: undefined: DemoClient

go version:1.13.4

go env:

GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/skymac/Library/Caches/go-build"
GOENV="/Users/skymac/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/skymac/sky_work/go_work"
GOPRIVATE=""
GOPROXY="https://goproxy.cn,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.google.cn"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/skymac/sky_work/go_work/src/kratos-demo/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/6w/7vfbqgyj2klckr8kyzqfj40c0000gn/T/go-build759567413=/tmp/go-build -gno-record-gcc-switches -fno-common"

go build 报错
../api/client.go:15:68: undefined: DemoClient
../api/client.go:21:9: undefined: NewDemoClient

go get 获取的是v0.3.1,请问怎么获取master(Go 新手,请多指教)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.