-
Notifications
You must be signed in to change notification settings - Fork 0
/
services.go
69 lines (53 loc) · 1.62 KB
/
services.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// +build go1.12
package main
import (
"context"
"fmt"
"net"
"net/http"
"github.com/grpc-ecosystem/grpc-gateway/runtime"
"google.golang.org/grpc"
)
func grpcServer(svc *OidcService, hostport string) {
nfd, err := net.Listen("tcp", hostport)
if err != nil {
panic(err)
}
fmt.Printf("starting grpc service\n")
grpcServer := grpc.NewServer()
RegisterOidcServer(grpcServer, svc)
err = grpcServer.Serve(nfd)
if err != nil {
panic(err)
}
}
func restServer(svc *OidcService, hostport string) {
var dialopts []grpc.DialOption
dialopts = append(dialopts, grpc.WithInsecure())
dialopts = append(dialopts, grpc.WithDefaultCallOptions(grpc.FailFast(true)))
dialopts = append(dialopts, grpc.WithBlock())
nfd, err := grpc.Dial(grpcConnect, dialopts...)
if err != nil {
panic(err)
}
grpcClient := NewOidcClient(nfd)
if err != nil {
panic(err)
}
runtime.HTTPError = svc.OidcHandleHTTPError
grpcmux := runtime.NewServeMux(
runtime.WithProtoErrorHandler(svc.OidcHandleHTTPError), // handle our library specific error codes.
runtime.WithForwardResponseOption(cookieOrRedirectMapper), // create the Location Header + state cookie for the auth
runtime.WithMetadata(headerToMetadata), // get the cookie and fill it in metadatas.
runtime.WithMarshalerOption(runtime.MIMEWildcard, &runtime.JSONPb{OrigName: true, EmitDefaults: true}),
)
err = RegisterOidcHandlerClient(context.Background(), grpcmux, grpcClient)
if err != nil {
panic(err)
}
fmt.Printf("starting rest-gateway service\n")
err = http.ListenAndServe(hostport, grpcmux) // serve that on 8080
panic(err)
}
func restOnlyServer() {
}