svc.tpl 488 B

12345678910111213141516171819202122
  1. package svc
  2. import (
  3. "{{.configPkg}}"{{if .callRPC}}
  4. "github.com/zeromicro/go-zero/zrpc"
  5. "{{.rpcClientPkg}}"{{end}}
  6. )
  7. type ServiceContext struct {
  8. Config config.Config{{if .callRPC}}
  9. GreetRpc greet.Greet{{end}}
  10. }
  11. func NewServiceContext(c config.Config) *ServiceContext {
  12. {{if .callRPC}}client := zrpc.MustNewClient(zrpc.RpcClientConf{
  13. Target: "127.0.0.1:8080",
  14. }){{end}}
  15. return &ServiceContext{
  16. Config: c,
  17. {{if .callRPC}}GreetRpc: greet.NewGreet(client),{{end}}
  18. }
  19. }