Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proxy: support standalone mode #1

Merged
merged 10 commits into from
Aug 11, 2022
Merged

proxy: support standalone mode #1

merged 10 commits into from
Aug 11, 2022

Conversation

zchee
Copy link
Member

@zchee zchee commented Aug 11, 2022

Support standalone mode.

protoc -I . -I ${HOME}/src/github.com/googleapis/googleapis --proxy_out=standalone=true,out=github.com/protobuf-tools/protoc-gen-proxy:./testdata ${HOME}/src/github.com/googleapis/googleapis/google/spanner/v1/*.proto
// Code generated by protoc-gen-proxy. DO NOT EDIT.

package spanner

import (
	context "context"
	errors "errors"
	v1 "google.golang.org/genproto/googleapis/spanner/v1"
	grpc "google.golang.org/grpc"
	emptypb "google.golang.org/protobuf/types/known/emptypb"
	net "net"
)

var _ emptypb.Empty

var ErrNotSupported = errors.New("operation not supported")

type spannerServer struct {
	proxy *Proxy
}

func (s *spannerServer) BatchCreateSessions(ctx context.Context, req *v1.BatchCreateSessionsRequest) (*v1.BatchCreateSessionsResponse, error) {
	fn := s.proxy.BatchCreateSessions
	if fn == nil {
		return nil, ErrNotSupported
	}

	return fn(ctx, req)
}

func (s *spannerServer) BeginTransaction(ctx context.Context, req *v1.BeginTransactionRequest) (*v1.Transaction, error) {
	fn := s.proxy.BeginTransaction
	if fn == nil {
		return nil, ErrNotSupported
	}

	return fn(ctx, req)
}

func (s *spannerServer) Commit(ctx context.Context, req *v1.CommitRequest) (*v1.CommitResponse, error) {
	fn := s.proxy.Commit
	if fn == nil {
		return nil, ErrNotSupported
	}

	return fn(ctx, req)
}

func (s *spannerServer) CreateSession(ctx context.Context, req *v1.CreateSessionRequest) (*v1.Session, error) {
	fn := s.proxy.CreateSession
	if fn == nil {
		return nil, ErrNotSupported
	}

	return fn(ctx, req)
}

func (s *spannerServer) DeleteSession(ctx context.Context, req *v1.DeleteSessionRequest) (*emptypb.Empty, error) {
	fn := s.proxy.DeleteSession
	if fn == nil {
		return nil, ErrNotSupported
	}

	return fn(ctx, req)
}

func (s *spannerServer) ExecuteBatchDml(ctx context.Context, req *v1.ExecuteBatchDmlRequest) (*v1.ExecuteBatchDmlResponse, error) {
	fn := s.proxy.ExecuteBatchDml
	if fn == nil {
		return nil, ErrNotSupported
	}

	return fn(ctx, req)
}

func (s *spannerServer) ExecuteSql(ctx context.Context, req *v1.ExecuteSqlRequest) (*v1.ResultSet, error) {
	fn := s.proxy.ExecuteSql
	if fn == nil {
		return nil, ErrNotSupported
	}

	return fn(ctx, req)
}

func (s *spannerServer) ExecuteStreamingSql(req *v1.ExecuteSqlRequest, srv v1.Spanner_ExecuteStreamingSqlServer) {
	fn := s.proxy.ExecuteStreamingSql
	if fn == nil {
		return nil, ErrNotSupported
	}

	return fn(ctx, req)
}

func (s *spannerServer) GetSession(ctx context.Context, req *v1.GetSessionRequest) (*v1.Session, error) {
	fn := s.proxy.GetSession
	if fn == nil {
		return nil, ErrNotSupported
	}

	return fn(ctx, req)
}

func (s *spannerServer) ListSessions(ctx context.Context, req *v1.ListSessionsRequest) (*v1.ListSessionsResponse, error) {
	fn := s.proxy.ListSessions
	if fn == nil {
		return nil, ErrNotSupported
	}

	return fn(ctx, req)
}

func (s *spannerServer) PartitionQuery(ctx context.Context, req *v1.PartitionQueryRequest) (*v1.PartitionResponse, error) {
	fn := s.proxy.PartitionQuery
	if fn == nil {
		return nil, ErrNotSupported
	}

	return fn(ctx, req)
}

func (s *spannerServer) PartitionRead(ctx context.Context, req *v1.PartitionReadRequest) (*v1.PartitionResponse, error) {
	fn := s.proxy.PartitionRead
	if fn == nil {
		return nil, ErrNotSupported
	}

	return fn(ctx, req)
}

func (s *spannerServer) Read(ctx context.Context, req *v1.ReadRequest) (*v1.ResultSet, error) {
	fn := s.proxy.Read
	if fn == nil {
		return nil, ErrNotSupported
	}

	return fn(ctx, req)
}

func (s *spannerServer) Rollback(ctx context.Context, req *v1.RollbackRequest) (*emptypb.Empty, error) {
	fn := s.proxy.Rollback
	if fn == nil {
		return nil, ErrNotSupported
	}

	return fn(ctx, req)
}

func (s *spannerServer) StreamingRead(req *v1.ReadRequest, srv v1.Spanner_StreamingReadServer) {
	fn := s.proxy.StreamingRead
	if fn == nil {
		return nil, ErrNotSupported
	}

	return fn(ctx, req)
}

// Proxy allows to create Spanner proxy servers.
type Proxy struct {
	BatchCreateSessions func(ctx context.Context, req *v1.BatchCreateSessionsRequest) (*v1.BatchCreateSessionsResponse, error)
	BeginTransaction    func(ctx context.Context, req *v1.BeginTransactionRequest) (*v1.Transaction, error)
	Commit              func(ctx context.Context, req *v1.CommitRequest) (*v1.CommitResponse, error)
	CreateSession       func(ctx context.Context, req *v1.CreateSessionRequest) (*v1.Session, error)
	DeleteSession       func(ctx context.Context, req *v1.DeleteSessionRequest) (*emptypb.Empty, error)
	ExecuteBatchDml     func(ctx context.Context, req *v1.ExecuteBatchDmlRequest) (*v1.ExecuteBatchDmlResponse, error)
	ExecuteSql          func(ctx context.Context, req *v1.ExecuteSqlRequest) (*v1.ResultSet, error)
	ExecuteStreamingSql func(req *v1.ExecuteSqlRequest, srv v1.Spanner_ExecuteStreamingSqlServer)
	GetSession          func(ctx context.Context, req *v1.GetSessionRequest) (*v1.Session, error)
	ListSessions        func(ctx context.Context, req *v1.ListSessionsRequest) (*v1.ListSessionsResponse, error)
	PartitionQuery      func(ctx context.Context, req *v1.PartitionQueryRequest) (*v1.PartitionResponse, error)
	PartitionRead       func(ctx context.Context, req *v1.PartitionReadRequest) (*v1.PartitionResponse, error)
	Read                func(ctx context.Context, req *v1.ReadRequest) (*v1.ResultSet, error)
	Rollback            func(ctx context.Context, req *v1.RollbackRequest) (*emptypb.Empty, error)
	StreamingRead       func(req *v1.ReadRequest, srv v1.Spanner_StreamingReadServer)
}

// Serve starts serving the proxy server on the given listener with the specified options.
func (p *Proxy) Serve(l net.Listener, opts ...grpc.ServerOption) error {
	srv := grpc.NewServer(opts...)
	v1.RegisterSpannerServer(srv, &spannerServer{proxy: p})

	return srv.Serve(l)
}

zchee added 8 commits August 9, 2022 11:31
Signed-off-by: Koichi Shiraishi <zchee.io@gmail.com>
Signed-off-by: Koichi Shiraishi <zchee.io@gmail.com>
Signed-off-by: Koichi Shiraishi <zchee.io@gmail.com>
Signed-off-by: Koichi Shiraishi <zchee.io@gmail.com>
Signed-off-by: Koichi Shiraishi <zchee.io@gmail.com>
Signed-off-by: Koichi Shiraishi <zchee.io@gmail.com>
Signed-off-by: Koichi Shiraishi <zchee.io@gmail.com>
Signed-off-by: Koichi Shiraishi <zchee.io@gmail.com>
@zchee zchee force-pushed the standalone branch 3 times, most recently from d24e676 to a88a669 Compare August 11, 2022 08:37
Signed-off-by: Koichi Shiraishi <zchee.io@gmail.com>
Signed-off-by: Koichi Shiraishi <zchee.io@gmail.com>
@zchee zchee merged commit 4f0af6a into main Aug 11, 2022
@zchee zchee deleted the standalone branch August 11, 2022 11:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant