-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
183 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package main | ||
|
||
import ( | ||
"log" | ||
"time" | ||
|
||
"github.com/sjy-dv/bridger/client" | ||
"github.com/sjy-dv/bridger/client/options" | ||
"google.golang.org/grpc/credentials" | ||
) | ||
|
||
/* | ||
If you are connecting to a pure gRPC server using SSL in Ingress, | ||
simply set Enable to true without any additional configuration. | ||
*/ | ||
func main() { | ||
/* | ||
not tls | ||
*/ | ||
// bridgerClient := client.RegisterBridgerClient(&options.Options{ | ||
// Addr: "127.0.0.1:50051", | ||
// MinChannelSize: 1, | ||
// MaxChannelSize: 4, | ||
// Timeout: time.Duration(time.Second * 5), | ||
// }) | ||
// defer bridgerClient.Close() | ||
/* | ||
using ca.cert | ||
*/ | ||
// b, _ := os.ReadFile("ca.cert") | ||
// cp := x509.NewCertPool() | ||
// if !cp.AppendCertsFromPEM(b) { | ||
// panic("credentials: failed to append certificates") | ||
// } | ||
// bridgerClient := client.RegisterBridgerClient(&options.Options{ | ||
// Addr: "127.0.0.1:50051", | ||
// MinChannelSize: 1, | ||
// MaxChannelSize: 4, | ||
// Timeout: time.Duration(time.Second * 5), | ||
// Credentials: options.Credentials{ | ||
// Enable: true, | ||
// TLS: &tls.Config{ | ||
// InsecureSkipVerify: false, | ||
// RootCAs: cp, | ||
// }, | ||
// }, | ||
// }) | ||
// defer bridgerClient.Close() | ||
/* | ||
using pem | ||
*/ | ||
creds, err := credentials.NewClientTLSFromFile("service.pem", "") | ||
if err != nil { | ||
log.Fatalf("could not process the credentials: %v", err) | ||
} | ||
bridgerClient := client.RegisterBridgerClient(&options.Options{ | ||
Addr: "127.0.0.1:50051", | ||
MinChannelSize: 1, | ||
MaxChannelSize: 4, | ||
Timeout: time.Duration(time.Second * 5), | ||
Credentials: options.Credentials{ | ||
Enable: true, | ||
Cred: creds, | ||
}, | ||
}) | ||
defer bridgerClient.Close() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package main | ||
|
||
import ( | ||
"log" | ||
|
||
"github.com/sjy-dv/bridger/server" | ||
"github.com/sjy-dv/bridger/server/dispatcher" | ||
"github.com/sjy-dv/bridger/server/options" | ||
"google.golang.org/grpc/credentials" | ||
) | ||
|
||
func main() { | ||
bridger := server.New() | ||
creds, err := credentials.NewServerTLSFromFile("service.pem", "service.key") | ||
if err != nil { | ||
log.Fatalf("Failed to setup TLS: %v", err) | ||
} | ||
bridger.Register("/greetings", greetings) | ||
bridger.Register("/greetings/withname", | ||
greetingsWithHeaderName, | ||
"is using metadata api") | ||
bridger.RegisterBridgerServer(&options.Options{ | ||
Port: 50051, | ||
ChainUnaryInterceptorLogger: true, | ||
ChainStreamInterceptorLogger: true, | ||
Credentials: options.Credentials{ | ||
Enable: true, | ||
Cred: creds, | ||
}, | ||
}) | ||
} | ||
|
||
func greetings(dtx dispatcher.DispatchContext) *dispatcher.ResponseWriter { | ||
var ( | ||
req = struct { | ||
Msg string | ||
}{} | ||
err error | ||
) | ||
err = dtx.Bind(&req) | ||
if err != nil { | ||
return dtx.Error(err) | ||
} | ||
req.Msg = req.Msg + "\n" + "Me too.." | ||
return dtx.Reply(&req) | ||
} | ||
|
||
func greetingsWithHeaderName(dtx dispatcher.DispatchContext) *dispatcher.ResponseWriter { | ||
var ( | ||
req = struct { | ||
Msg string | ||
}{} | ||
err error | ||
) | ||
err = dtx.Bind(&req) | ||
if err != nil { | ||
return dtx.Error(err) | ||
} | ||
name := dtx.GetMetadata("name") | ||
req.Msg = "Hello " + name | ||
return dtx.Reply(&req) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters