proxy

package module
v0.0.0-...-79d72c4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 5, 2020 License: Apache-2.0 Imports: 6 Imported by: 0

README

spanner-proxy

An easy way to create Google Cloud Spanner proxies...

See examples/proxy for an example proxy server.

p := proxy.New()
p.CreateSession = func(ctx context.Context, req *pb.CreateSessionRequest) (*pb.Session, error) {
    // Your own session creation...
    return &pb.Session{
        Name:       "my-first-session",
        CreateTime: ptypes.TimestampNow(),
    }, nil
}
log.Fatal(p.Serve(lis))

Proxy is honored by the official Cloud Spanner libraries automatically if you set SPANNER_EMULATOR_HOST environment variable to the proxy endpoint.

export SPANNER_EMULATOR_HOST=localhost:9777
go run examples/client/main.go

Alternatively, you can use the Cloud Spanner gRPC clients with the proxy endpoint and insecure connection:

conn, err := grpc.Dial("localhost:9777", grpc.WithInsecure())
if err != nil {
    log.Fatal(err)
}
defer conn.Close()

When to write a proxy server?

There are various reasons you might want to write a proxy server. Some examples:

  • To override the behavior of the Cloud Spanner API.
  • To manage connections and sessions outside of application server.
  • To instrument the Cloud Spanner calls in a custom way for monitoring and debugging purposes.
  • To handle the authentication to Cloud Spanner outside of the application servers.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Proxy

type Proxy struct {
	CreateSession       func(ctx context.Context, req *pb.CreateSessionRequest) (*pb.Session, error)
	BatchCreateSessions func(ctx context.Context, req *pb.BatchCreateSessionsRequest) (*pb.BatchCreateSessionsResponse, error)
	GetSession          func(ctx context.Context, req *pb.GetSessionRequest) (*pb.Session, error)
	ListSessions        func(ctx context.Context, req *pb.ListSessionsRequest) (*pb.ListSessionsResponse, error)
	DeleteSession       func(ctx context.Context, req *pb.DeleteSessionRequest) (*empty.Empty, error)
	ExecuteSQL          func(ctx context.Context, req *pb.ExecuteSqlRequest) (*pb.ResultSet, error)
	ExecuteStreamingSQL func(req *pb.ExecuteSqlRequest, s pb.Spanner_ExecuteStreamingSqlServer) error
	ExecuteBatchDML     func(ctx context.Context, req *pb.ExecuteBatchDmlRequest) (*pb.ExecuteBatchDmlResponse, error)
	Read                func(ctx context.Context, req *pb.ReadRequest) (*pb.ResultSet, error)
	StreamingRead       func(req *pb.ReadRequest, s pb.Spanner_StreamingReadServer) error
	BeginTransaction    func(ctx context.Context, req *pb.BeginTransactionRequest) (*pb.Transaction, error)
	Commit              func(ctx context.Context, req *pb.CommitRequest) (*pb.CommitResponse, error)
	Rollback            func(ctx context.Context, req *pb.RollbackRequest) (*empty.Empty, error)
	PartitionQuery      func(ctx context.Context, req *pb.PartitionQueryRequest) (*pb.PartitionResponse, error)
	PartitionRead       func(ctx context.Context, req *pb.PartitionReadRequest) (*pb.PartitionResponse, error)
}

Proxy allows to create Google Cloud Spanner proxy servers. In order to override behavior, implement the functions. If user calls an unimplemented function, the proxy will return and error saying operation is not supported.

func New

func New() *Proxy

New creates a new proxy.

func (*Proxy) Serve

func (p *Proxy) Serve(l net.Listener, opt ...grpc.ServerOption) error

Serve starts serving the proxy server on the given listener with the specified options.

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL