zoukankan      html  css  js  c++  java
  • golang笔记

    定义结构类型值时,如果带有结构字段名,最后一个字段后加逗号,比如

    mark := user{

        name: "Mark",

        email: "mark@email.com",

    },此时字段之间没有顺序要求,另一种

    声明对象方法时,接收器有值接收器和指针接收器,对值接收器声明的方法而言,调用时使用值的一个副本来执行

    grpc相关:

    https://github.com/grpc/grpc-go/   有mod场景下的被墙后的设置

    https://github.com/golang/protobuf  proto文件中定义了service可直接生成grpc

    protoc相关

    https://github.com/grpc/grpc-go/tree/master/examples/helloworld

    这里也有mock的应用

    mock

    参考  https://www.jianshu.com/p/598a11bbdafb

    export GOPROXY="http://goproxy.io"

    export GO111MODULE="on"

    目录结构:

    ~/gopath/src/github.com/wang/grpcexamples/helloworld/

    ~/gopath/src/github.com/wang/grpcexamples/helloworld/helloworld/helloworld.proto

    ~/gopath/src/github.com/wang/grpcexamples/helloworld/helloworld/helloworld.pb.go

    ~/gopath/src/github.com/wang/grpcexamples/helloworld/helloworld/greeter_client/main.go

    ~/gopath/src/github.com/wang/grpcexamples/helloworld/helloworld/greeter_server/main.go

    ~/gopath/src/github.com/wang/grpcexamples/helloworld/helloworld/mock_helloworld/

    命令:

    ~/gopath/src/github.com/wang/grpcexamples/helloworld/$ go mod init "github.com/wang/grpcexamples/helloworld"

    ~/gopath/src/github.com/wang/grpcexamples/helloworld/helloworld$protoc -I helloworld/ helloworld/helloworld.proto  --go_out=plugins=grpc:helloworld

    ~/gopath/src/github.com/wang/grpcexamples/helloworld/helloworld$ go build   #这里会进行mod更新

    ####修改server & client的main.go的包路径,然后

    ~/gopath/src/github.com/wang/grpcexamples/helloworld/greeter_server$ go build

    ~/gopath/src/github.com/wang/grpcexamples/helloworld/greeter_client$ go build

    ~/gopath/src/github.com/wang/grpcexamples/helloworld$ mockgen -destination mock_helloworld/hw_mock_server.go  -package helloworld github.com/wang/grpcexamples/helloworld/helloworld GreeterServer

    ~/gopath/src/github.com/wang/grpcexamples/helloworld$  mockgen -destination mock_helloworld/hw_mock_client.go  -package helloworld github.com/wang/grpcexamples/helloworld/helloworld GreeterClient

    ###mockgen --destination 生成的文件路径 -package 源包名字 源包路径 源接口名字

    ###mock是针对interface的,模拟接口的行为

  • 相关阅读:
    hdu 5972 Regular Number
    hdu 5971 Wrestling Match
    福大软工 · BETA 版冲刺前准备(团队)
    福大软工 · 第十一次作业
    Alpha 冲刺 (10/10)
    Alpha 冲刺 (9/10)
    Alpha 冲刺 (8/10)
    Alpha 冲刺 (7/10)
    Alpha 冲刺 (6/10)
    Alpha 冲刺 (5/10)
  • 原文地址:https://www.cnblogs.com/dablyo/p/10801916.html
Copyright © 2011-2022 走看看