printfcoder / stack-rpc-tutorials

Stack-RPC 中文示例、教程、资料,源码解读
https://stacklabs.cn
Apache License 2.0
1.69k stars 302 forks source link

Go夜读第二期-【工程实践】Go-Micro编写微服务 #165

Closed printfcoder closed 4 years ago

printfcoder commented 5 years ago

本期内容

  1. 使用Go-Micro编写微服务
  2. Go-Micro的特性
  3. 待述

第一期:https://github.com/micro-in-cn/tutorials/issues/100 第一期资料:Bilibili, GoogleDocs Go 夜读:https://github.com/developer-learning/night-reading-go/issues/504

heyuanchao commented 4 years ago

go get -u github.com/micro/micro 报错

C:\Users\admin>go get -u github.com/micro/micro
# github.com/micro/go-micro/transport/quic
go\src\github.com\micro\go-micro\transport\quic\quic.go:121:3: unknown field 'IdleTimeout' in struct literal of type quic.Config
# github.com/coreos/etcd/clientv3
go\src\github.com\coreos\etcd\clientv3\auth.go:121:72: cannot use auth.callOpts (type []"github.com/coreos/etcd/vendor/google.golang.org/grpc".CallOption) as type []"go.etcd.io/etcd/vendor/google.golang.org/grpc".CallOption in argument to auth.remote.AuthEnable
go\src\github.com\coreos\etcd\clientv3\auth.go:126:74: cannot use auth.callOpts (type []"github.com/coreos/etcd/vendor/google.golang.org/grpc".CallOption) as type []"go.etcd.io/etcd/vendor/google.golang.org/grpc".CallOption in argument to auth.remote.AuthDisable
go\src\github.com\coreos\etcd\clientv3\auth.go:131:152: cannot use auth.callOpts (type []"github.com/coreos/etcd/vendor/google.golang.org/grpc".CallOption) as type []"go.etcd.io/etcd/vendor/google.golang.org/grpc".CallOption in argument to auth.remote.UserAdd
go\src\github.com\coreos\etcd\clientv3\auth.go:136:144: cannot use auth.callOpts (type []"github.com/coreos/etcd/vendor/google.golang.org/grpc".CallOption) as type []"go.etcd.io/etcd/vendor/google.golang.org/grpc".CallOption in argument to auth.remote.UserAdd
go\src\github.com\coreos\etcd\clientv3\auth.go:141:86: cannot use auth.callOpts (type []"github.com/coreos/etcd/vendor/google.golang.org/grpc".CallOption) as type []"go.etcd.io/etcd/vendor/google.golang.org/grpc".CallOption in argument to auth.remote.UserDelete
go\src\github.com\coreos\etcd\clientv3\auth.go:146:122: cannot use auth.callOpts (type []"github.com/coreos/etcd/vendor/google.golang.org/grpc".CallOption) as type []"go.etcd.io/etcd/vendor/google.golang.org/grpc".CallOption in argument to auth.remote.UserChangePassword
go\src\github.com\coreos\etcd\clientv3\auth.go:151:104: cannot use auth.callOpts (type []"github.com/coreos/etcd/vendor/google.golang.org/grpc".CallOption) as type []"go.etcd.io/etcd/vendor/google.golang.org/grpc".CallOption in argument to auth.remote.UserGrantRole
go\src\github.com\coreos\etcd\clientv3\auth.go:156:80: cannot use auth.callOpts (type []"github.com/coreos/etcd/vendor/google.golang.org/grpc".CallOption) as type []"go.etcd.io/etcd/vendor/google.golang.org/grpc".CallOption in argument to auth.remote.UserGet
go\src\github.com\coreos\etcd\clientv3\auth.go:161:72: cannot use auth.callOpts (type []"github.com/coreos/etcd/vendor/google.golang.org/grpc".CallOption) as type []"go.etcd.io/etcd/vendor/google.golang.org/grpc".CallOption in argument to auth.remote.UserList
go\src\github.com\coreos\etcd\clientv3\auth.go:166:106: cannot use auth.callOpts (type []"github.com/coreos/etcd/vendor/google.golang.org/grpc".CallOption) as type []"go.etcd.io/etcd/vendor/google.golang.org/grpc".CallOption in argument to auth.remote.UserRevokeRole
go\src\github.com\coreos\etcd\clientv3\auth.go:166:106: too many errors
printfcoder commented 4 years ago

@heyuanchao 你好,使用gomod,不要用gopath

heyuanchao commented 4 years ago

运行 https://github.com/micro-in-cn/tutorials/tree/master/examples/basic-practices/micro-api/rpc 中的例子报错

# curl -H 'Content-Type: application/json' -d '{"name": "小小先"}' "http://localhost:8080/example/call"
POST http://localhost:8080/example/call
Content-Type: application/json

{"name": "小小先"}
{"id":"go.micro.api","code":500,"detail":"error during request: unknown field \"name\" in go_api.Request","status":"Internal Server Error"}

我改了下代码:

if req.Method != "POST" {
        return errors.BadRequest("go.micro.api.example", "method: [%v], require post", req.Method)
    }
# curl -H 'Content-Type: application/json' -d '{}' http://localhost:8080/example/foo/bar
POST http://localhost:8080/example/foo/bar
Content-Type: application/json
{"id":"go.micro.api.example","code":400,"detail":"method: [], require post","status":"Bad Request"}
printfcoder commented 4 years ago

@heyuanchao 请不要在无关issue下问无关的问题,需要新建issue

printfcoder commented 4 years ago

本期分享结束,关闭问题