github.com/cloudwego/kitex@v0.9.0/pkg/generic/httppb_test/generic_init.go (about) 1 /* 2 * Copyright 2021 CloudWeGo Authors 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 // Package test ... 18 package test 19 20 import ( 21 "context" 22 "net" 23 "time" 24 25 "github.com/cloudwego/kitex/client" 26 "github.com/cloudwego/kitex/client/genericclient" 27 "github.com/cloudwego/kitex/pkg/generic" 28 "github.com/cloudwego/kitex/server" 29 "github.com/cloudwego/kitex/server/genericserver" 30 ) 31 32 func newGenericClient(destService string, g generic.Generic, targetIPPort string) genericclient.Client { 33 var opts []client.Option 34 opts = append(opts, client.WithHostPorts(targetIPPort)) 35 genericCli, _ := genericclient.NewClient(destService, g, opts...) 36 return genericCli 37 } 38 39 func newGenericServer(g generic.Generic, addr net.Addr, handler generic.Service) server.Server { 40 var opts []server.Option 41 opts = append(opts, server.WithServiceAddr(addr), server.WithExitWaitTime(time.Millisecond*10)) 42 svr := genericserver.NewServer(handler, g, opts...) 43 go func() { 44 err := svr.Run() 45 if err != nil { 46 panic(err) 47 } 48 }() 49 return svr 50 } 51 52 // GenericServiceReadRequiredFiledImpl ... 53 type GenericServiceEchoImpl struct{} 54 55 // GenericCall ... 56 func (g *GenericServiceEchoImpl) GenericCall(ctx context.Context, method string, request interface{}) (response interface{}, err error) { 57 req := request.(map[string]interface{}) 58 return req, nil 59 }