Giter VIP home page Giter VIP logo

Comments (12)

printfcoder avatar printfcoder commented on June 27, 2024

明显有问题 MICRO_REGISRY_ADDRESS -> MICRO_REGISTRY_ADDRESS

from stack-rpc-tutorials.

printfcoder avatar printfcoder commented on June 27, 2024

但是写错MICRO_REGISRY_ADDRESS这个相当于没有写,会默认使用127.0.0.1,也就相当于是192.168.1.3

from stack-rpc-tutorials.

printfcoder avatar printfcoder commented on June 27, 2024

是user-api->user-srv这一步不通?把代码脱敏放上来看看

from stack-rpc-tutorials.

bluedragonflyliu avatar bluedragonflyliu commented on June 27, 2024

我想用一个最简单的例子看看有没有我提到的问题但是却出现另外一个问题
我在目录micro_demo创建应用
micro version 1.9.1

  1. micro new micro_demo/api/user --type api --namespace com.abc
  2. micro new micro_demo/srv/user --type srv --namespace com.abc
  3. protoc --proto_path=$GOPATH/src:. --go_out=. --micro_out=. srv/user/proto/user/user.proto
  4. protoc --proto_path=$GOPATH/src:. --go_out=. --micro_out=. api/user/proto/user/user.proto
  5. 修改api user里的client 和 handler 的srv user proto引入路径修改成 user "micro_demo/srv/user/proto/user"
  6. 进入目录运行 api/user 和 srv/user

go run main.go --registry=consul --registry_address=192.168.1.3
srv/user 运行
但是api/user build command-line-arguments: cannot load micro_demo/srv/user/proto/user: cannot find module providing package micro_demo/srv/user/proto/user

from stack-rpc-tutorials.

printfcoder avatar printfcoder commented on June 27, 2024

micro_demo/srv/user/proto/user -> github.com/你的site/micro_demo/srv/....,或其它domain下。参考gopath下的每个公司的包名路径

from stack-rpc-tutorials.

bluedragonflyliu avatar bluedragonflyliu commented on June 27, 2024

问题依旧在
go 是GOPATH路径
go/src/github.com/mytest/micro_demo/api/user
micro new srv/user api/user 后
protoc 运行完
问题还是srv正常运行api cannot load github.com/mytest/micro_demo/srv/user/proto/user: cannot find module providing package github.com/mytest/micro_demo/srv/user/proto/user
go version go1.12.9 linux/amd64

from stack-rpc-tutorials.

printfcoder avatar printfcoder commented on June 27, 2024

把代码传到你的仓库中,我看看

from stack-rpc-tutorials.

bluedragonflyliu avatar bluedragonflyliu commented on June 27, 2024

https://github.com/bluedragonflyliu/micro_demo

from stack-rpc-tutorials.

bluedragonflyliu avatar bluedragonflyliu commented on June 27, 2024

关于第一个有关consul的问题,好像知道表面原因了,是新的micro创建client的方式和以前不一样了

from stack-rpc-tutorials.

bluedragonflyliu avatar bluedragonflyliu commented on June 27, 2024

micro new 找不到srv/user/proto/user 的问题我又试了一下

  1. 新建虚机centos7 最新的
  2. 安上micro 的环境和依赖
  3. micro new 新建
  4. 运行protoc --proto_path=.:$GOPATH/src --go_out=. --micro_out=. mytest/api/user/proto/user/user.proto 会提示 github.com/micro/go-micro/api/proto/api.proto: File not found.
  5. 直接git clone后protoc 通过
  6. 将 api/user 里client 和 handler 依赖改成现有srv/user/proto/user
  7. 运行srv/user 正常
  8. 运行api/user 还是找不到srv/user/proto

go env
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/root/go"
GOPRIVATE=""
GOPROXY="https://goproxy.io"
GOROOT="/usr/local/bin/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/bin/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/go/src/github.com/abc/mytest/srv/user/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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build962096667=/tmp/go-build -gno-record-gcc-switches"

from stack-rpc-tutorials.

printfcoder avatar printfcoder commented on June 27, 2024

Emm,我感觉生成proto文件的那一步指令很奇怪。一般我是切到服务proto目录的上级,相当于micro_demo/api/user目录,然后执行命令,命令参考如下:

protoc --proto_path=.:$GOPATH/src --go_out=. --micro_out=. ./proto/user/user.proto

这样生成的文件与引用方式就是很干净的,不清楚为什么要加上mytest这个与项目目录并不相关的目录。

引用大致如下:

import (
	"github.com/bluedragonflyliu/micro_demo/micro_demo/api/user/client"
	user "github.com/bluedragonflyliu/micro_demo/micro_demo/api/user/proto/user"
	"github.com/micro/go-micro"
	"github.com/micro/go-micro/util/log"
)

from stack-rpc-tutorials.

bluedragonflyliu avatar bluedragonflyliu commented on June 27, 2024

是模板中go.mod的问题

from stack-rpc-tutorials.

Related Issues (20)

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.