Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

请问 怎么编写 go-micro 的 example 函数?

我写了一个 go-micro 的插件,想写一个示例函数,但是没办法运行,报错

Incorrect Usage. flag provided but not defined: -test.testlogfile

micro 版本:1.18
go 版本:1.14
系统: win10

我写的中间件应该是没问题的,测试过都可以正常运行,但是示例不知道要怎么写。。。
下面是我在 example 中写的部分代码,文件名函数名都是按照规范写的。
截图:运行 go test -v ./ 时出现下面的输出
image.png

部分代码:

//create test server
 service := micro.NewService(
      micro.Name("greeter"),
 micro.WrapHandler(NewHandlerWrapper(tracer)),
 )
   // initialise command line
 service.Init()
   // set the handler
 micro.RegisterHandler(service.Server(), new(Greeter))
   // run service
 service.Run()
 
 //Create client service
   cli := micro.NewService(
      micro.Name("micro_client"),
 micro.WrapClient(NewClientWrapper(tracer)),
 )
   cli.Init()
   c := cli.Client()
   request := c.NewRequest("greeter", "Greeter.Hello", "john", client.WithContentType("application/json"))
   var response string
 for i := 0; i < 100; i++ {
      time.Sleep(time.Millisecond * 100)
      if err := c.Call(context.TODO(), request, &response); err != nil {
         log.Fatalf("call service err %v n", err)
      }
   }
   log.Fatalf("response: %v n", response)
//Output:

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

image.png
加号点开,看下具体的运行参数是不是带了

-test.testlogfile

如果是,在 run > params 看下是否有参数,有的话就清除掉。

image.png


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...