Last active
January 9, 2023 06:54
-
-
Save epk/d077654d4e1f97718d528bc391aae0ff to your computer and use it in GitHub Desktop.
Envoy ALS
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
module test | |
go 1.19 | |
require ( | |
buf.build/gen/go/envoyproxy/envoy/bufbuild/connect-go v1.4.1-20221219165829-f29edaef12a2.1 | |
buf.build/gen/go/envoyproxy/envoy/protocolbuffers/go v1.28.1-20221219165829-f29edaef12a2.4 | |
github.com/bufbuild/connect-go v1.4.1 | |
github.com/bufbuild/connect-grpchealth-go v1.0.0 | |
golang.org/x/net v0.4.0 | |
) | |
require ( | |
buf.build/gen/go/cncf/xds/protocolbuffers/go v1.28.1-20221129150241-9994d403088d.4 // indirect | |
buf.build/gen/go/envoyproxy/protoc-gen-validate/protocolbuffers/go v1.28.1-20221025150516-6607b10f00ed.4 // indirect | |
golang.org/x/text v0.5.0 // indirect | |
google.golang.org/protobuf v1.28.1 // indirect | |
) |
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
package main | |
import ( | |
"context" | |
"fmt" | |
"net/http" | |
"os" | |
connect_go "github.com/bufbuild/connect-go" | |
grpchealth "github.com/bufbuild/connect-grpchealth-go" | |
"golang.org/x/net/http2" | |
"golang.org/x/net/http2/h2c" | |
"buf.build/gen/go/envoyproxy/envoy/bufbuild/connect-go/envoy/service/accesslog/v3/accesslogv3connect" | |
v3 "buf.build/gen/go/envoyproxy/envoy/protocolbuffers/go/envoy/service/accesslog/v3" | |
) | |
var _ = accesslogv3connect.AccessLogServiceHandler(&foo{}) | |
type foo struct{} | |
func (f *foo) StreamAccessLogs(ctx context.Context, req *connect_go.ClientStream[v3.StreamAccessLogsMessage]) (*connect_go.Response[v3.StreamAccessLogsResponse], error) { | |
for _, entry := range req.Msg().GetTcpLogs().GetLogEntry() { | |
fmt.Println(entry.GetCommonProperties().GetTlsProperties().GetTlsSniHostname()) | |
} | |
return connect_go.NewResponse(&v3.StreamAccessLogsResponse{}), nil | |
} | |
func main() { | |
mux := http.NewServeMux() | |
// gRPC health check | |
checker := grpchealth.NewStaticChecker( | |
accesslogv3connect.AccessLogServiceName, | |
) | |
mux.Handle(grpchealth.NewHandler(checker)) | |
mux.Handle(accesslogv3connect.NewAccessLogServiceHandler(&foo{})) | |
srv := &http.Server{ | |
Addr: ":50051", | |
Handler: h2c.NewHandler(mux, &http2.Server{}), | |
} | |
err := srv.ListenAndServe() | |
if err != nil { | |
fmt.Println(err) | |
os.Exit(1) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment