2022-05-13 12:23:24 +08:00
|
|
|
package svc
|
|
|
|
|
|
|
|
import (
|
2022-06-26 22:37:15 +08:00
|
|
|
"{{.configPkg}}"{{if .callRPC}}
|
2022-05-13 23:10:55 +08:00
|
|
|
"github.com/zeromicro/go-zero/zrpc"
|
2022-06-26 22:37:15 +08:00
|
|
|
"{{.rpcClientPkg}}"{{end}}
|
2022-05-13 12:23:24 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
type ServiceContext struct {
|
2022-06-26 22:37:15 +08:00
|
|
|
Config config.Config{{if .callRPC}}
|
|
|
|
GreetRpc greet.Greet{{end}}
|
2022-05-13 12:23:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewServiceContext(c config.Config) *ServiceContext {
|
2022-06-26 22:37:15 +08:00
|
|
|
{{if .callRPC}}client := zrpc.MustNewClient(zrpc.RpcClientConf{
|
2022-05-13 23:10:55 +08:00
|
|
|
Target: "127.0.0.1:8080",
|
2022-06-26 22:37:15 +08:00
|
|
|
}){{end}}
|
2022-05-13 23:10:55 +08:00
|
|
|
return &ServiceContext{
|
|
|
|
Config: c,
|
2022-06-26 22:37:15 +08:00
|
|
|
{{if .callRPC}}GreetRpc: greet.NewGreet(client),{{end}}
|
2022-05-13 23:10:55 +08:00
|
|
|
}
|
2022-05-13 12:23:24 +08:00
|
|
|
}
|