Skip to content

Commit

Permalink
Merge cbe2ecb into a1dfd71
Browse files Browse the repository at this point in the history
  • Loading branch information
seeflood authored Dec 10, 2021
2 parents a1dfd71 + cbe2ecb commit 0325272
Show file tree
Hide file tree
Showing 25 changed files with 1,492 additions and 380 deletions.
6 changes: 6 additions & 0 deletions cmd/layotto/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package main
import (
"encoding/json"
"fmt"
"mosn.io/layotto/pkg/grpc/default_api"
"os"
"strconv"
"time"
Expand Down Expand Up @@ -116,6 +117,7 @@ import (
"google.golang.org/grpc"
_ "mosn.io/layotto/pkg/filter/network/tcpcopy"
"mosn.io/layotto/pkg/runtime"
_ "mosn.io/layotto/pkg/wasm"
"mosn.io/mosn/pkg/featuregate"
_ "mosn.io/mosn/pkg/filter/network/grpc"
mgrpc "mosn.io/mosn/pkg/filter/network/grpc"
Expand Down Expand Up @@ -153,6 +155,10 @@ func NewRuntimeGrpcServer(data json.RawMessage, opts ...grpc.ServerOption) (mgrp
// 3. run
server, err := rt.Run(
runtime.WithGrpcOptions(opts...),
// register your grpc API here
runtime.WithGrpcAPI(
default_api.NewGrpcAPI,
),
// Hello
runtime.WithHelloFactory(
hello.NewHelloFactory("helloworld", helloworld.NewHelloWorld),
Expand Down
58 changes: 58 additions & 0 deletions cmd/layotto_multiple_api/client/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
*
* Copyright 2015 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

// Package main implements a client for Greeter service.
package main

import (
"context"
"log"
"os"
"time"

"google.golang.org/grpc"
pb "google.golang.org/grpc/examples/helloworld/helloworld"
)

const (
address = "localhost:34904"
defaultName = "world"
)

func main() {
// Set up a connection to the server.
conn, err := grpc.Dial(address, grpc.WithInsecure(), grpc.WithBlock())
if err != nil {
log.Fatalf("did not connect: %v", err)
}
defer conn.Close()
c := pb.NewGreeterClient(conn)

// Contact the server and print out its response.
name := defaultName
if len(os.Args) > 1 {
name = os.Args[1]
}
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
r, err := c.SayHello(ctx, &pb.HelloRequest{Name: name})
if err != nil {
log.Fatalf("could not greet: %v", err)
}
log.Printf("Greeting: %s", r.GetMessage())
}
Loading

0 comments on commit 0325272

Please sign in to comment.