go-kiss / sniper Goto Github PK
View Code? Open in Web Editor NEW轻量级 go 业务框架
Home Page: https://taoshu.in/go/sniper.html
License: MIT License
轻量级 go 业务框架
Home Page: https://taoshu.in/go/sniper.html
License: MIT License
默认rpc下会生成版本v1,例如 app/v1/service.proto
对应的server会生成 --> appserver1
请问是不是应当对应的创建: rpc(app/v1/service.proto) --> server(appserver1)-->service(appservice1) --> dao(appdao1)
安装不了
go install github.com/go-kiss/sniper/cmd/sniper@latest
go: github.com/go-kiss/sniper/cmd/sniper@latest: module github.com/go-kiss/sniper/cmd/sniper: Get "https://proxy.golang.com.cn/github.com/go-kiss/sniper/cmd/sniper/@v/list": EOF
获取数据并返回Todo的对象的json的代码块
func (s *Server) Read(ctx context.Context, req *pb.ReadRequest) (*pb.ReadResponse, error) {
var ida int64
var title string
var desc string
result, err := todo.Read(1)
defer result.Close()
for result.Next() {
result.Scan(&ida, &title, &desc)
break
}
log.Get(ctx).Infof("%d %s %s", ida, title, desc)
todo := &pb.ToDo{Id: ida, Title: title, Description: desc}
resp := &pb.ReadResponse{Api: "1", ToDo: todo}
log.Get(ctx).Infof("todo=%v", todo)
log.Get(ctx).Infof("resp=%v", resp)
return resp, err
}
程序执行结果的部分,todo和resp的结果都OK,write response时提示超时的错误信息。
INFO[0016] todo=id:1 title:"a" description:"b" app_id=localapp device="<nil>" env=dev instance_id=mac.local mobi_app="<nil>" platform="<nil>" trace_id=bc7f7c4690d3ef5 uid="<nil>" version="<nil>"
INFO[0016] resp=api:"1" toDo:<id:1 title:"a" description:"b" > app_id=localapp device="<nil>" env=dev instance_id=mac.local mobi_app="<nil>" platform="<nil>" trace_id=bc7f7c4690d3ef5 uid="<nil>" version="<nil>"
ERRO[0176] twirp error unknown: failed to write response, 0 of 59 bytes written: http: Handler timeout app_id=localapp device="<nil>" env=dev instance_id=mac.local mobi_app="<nil>" platform="<nil>" trace_id=bc7f7c4690d3ef5 uid="<nil>" version="<nil>"
service.twirp.go的代码出现的错误
函数:serveReadForm
if n, err := resp.Write(respBytes); err != nil {
msg := fmt.Sprintf("failed to write response, %d of %d bytes written: %s", n, len(respBytes), err.Error())
rpc/README.md 这里的 protoc-gen-twirp
是个死链接。正确的是 bilibili/twirp/protoc-gen-twirp 这个插件吗?
Line 14 in 1df02d5
因为业务需要,想在windows起一套内部服务,但是想到编译的时候会因为一些windows的包或者linux的包无法编译。
想请问一下如何较好的解决这个问题?
如果外部服务调用内部服务的话,是直接用tiwrp生成的client来请求还是写http请求?这个请求是否应该是在外部服务的dao层?
上次我提了一个dao层复用的问题,今天又遇到一个基础类型的protoc如何复用的问题:
shopAdmin protoc:
message goods{...}
shopFront protoc:
message goods{...}
这两个protoc都有goods这个基础的类型,如何做才能比较优美的实现复用?
安装所需扩展、执行git clone https://github.com/bilibili/sniper.git
.、执行go run cmd/sniper/main.go rpc --service=foo
均无报错.
但执行go run main.go server --port=8080
时出错
build command-line-arguments: cannot load sniper/cmd/falsework: malformed module path "sniper/cmd/falsework": missing dot in first path element
删除掉main.go的falsework内容后重新执行,出错改为
# sniper/cmd/server
cmd/server/http.go:28:33: cannot use hooks (type *"github.com/bilibili/twirp".ServerHooks) as type *"github.com/twitchtv/twirp".ServerHooks in argument to foo_v1.NewFooServer
cmd/server/main.go:137:9: too many arguments in call to initMux
have (*http.ServeMux, bool)
want (*http.ServeMux)
请问如何解决?望回复,谢谢
In function c.ExecTx(), you should execute a transaction by calling function ExecContext() with interface tx, not DB struct c.
B站前有 kratos 后有 sniper ,如何选型呢?
在使用过程中,发觉model不太好处理,我准备用的是http://gorm.io。目前方案有两种:
现在只有脚手架模板,没有其他DEMO
The codahale/hdrhistogram repo has been transferred under the github HdrHstogram umbrella with the help from the original author in Sept 2020 (new repo url https://github.com/HdrHistogram/hdrhistogram-go). The main reasons are to group all implementations under the same roof and to provide more active contribution from the community as the original repository was archived several years ago.
The dependency URL should be modified to point to the new repository URL. The tag "v0.9.0" was applied at the point of transfer and will reflect the exact code that was frozen in the original repository.
If you are using Go modules, you can update to the exact point of transfer using the @v0.9.0 tag in your go get command.
go mod edit -replace github.com/codahale/hdrhistogram=github.com/HdrHistogram/[email protected]
From the point of transfer, up until now (mon 16 aug 2021), we've released 3 versions that aim support the standard HdrHistogram serialization/exposition formats, and deeply improve READ performance.
We recommend to update to the latest version.
据我所知,b站已有一套开源的go微服务框架kratos,里面的功能也比较完备。
请问,为何不使用kratos这套框架,而要重新造个“轮子”呢?
期待答复
拿GetArticleDetail这个服务做例子:
rpc GetArticleDetail(GetArticleDetailRequest) returns (GetArticleDetailResponse)
目前sniper的访问顺序依次是:
server(param GetArticleDetailRequest) --> service (param GetArticleDetailRequest)--> dao(param GetArticleDetailRequest)
那么,
请问sniper在部署的时候如何使用envoy?是不是所有的http访问都先经过envoy,由envoy中转。能否分享一下sniper使用envoy的实践经验。由于envoy的文章很少,根据thought.md中的描述
对于 redis 和 http 服务,我们用的是 envoy。
拜托分享一下envoy的实践。
目前指向这里 https://github.com/bilibili/sniper/blob/master/server/README.md
显示 404 not found
看目前的结构,应该改成 /service/README.md
我们在使用sniper的过程中,dao层的复用拿捏不太准,例如:有两个服务
--shopAdmin(商城后端服务接口)
-- shopAdminDao
--shopHome(商城前端服务接口)
--shopHomeDao
在dao层有很多方法可以复用(例如:获取商品详情),这个应当通过[内部服务service的接口]去调用,还是dao层直接通过代码依赖来调用来实现代码的复用呢?那种调用方式更合理呢?
有没有完整点的示例?
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.