Documentation
¶
Index ¶
- Constants
- Variables
- type API
- type ConfigProvider
- type Handler
- func (h *Handler) API() *API
- func (h *Handler) Addr() string
- func (h *Handler) ExtractOperation(*echo.Context) string
- func (h *Handler) ExtractResource(*echo.Context) string
- func (h *Handler) GetSupportedOperations() []string
- func (h *Handler) Handler() echo.HandlerFunc
- func (h *Handler) MatchPriority() int
- func (h *Handler) Name() string
- func (h *Handler) Reset()
- func (h *Handler) Restore(ctx context.Context, data []byte) error
- func (h *Handler) RouteMatcher() service.Matcher
- func (h *Handler) Shutdown(ctx context.Context)
- func (h *Handler) Snapshot(ctx context.Context) []byte
- func (h *Handler) StartWorker(ctx context.Context) error
- type InMemoryBackend
- func (b *InMemoryBackend) Close()
- func (b *InMemoryBackend) CreateDatabase(ctx context.Context, in *databasepb.CreateDatabaseRequest) (*longrunningpb.Operation, error)
- func (b *InMemoryBackend) CreateInstance(in *instancepb.CreateInstanceRequest) (*longrunningpb.Operation, error)
- func (b *InMemoryBackend) DeleteInstance(name string) (*emptypb.Empty, error)
- func (b *InMemoryBackend) DropDatabase(ctx context.Context, name string) (*emptypb.Empty, error)
- func (b *InMemoryBackend) GetDatabase(name string) (*databasepb.Database, error)
- func (b *InMemoryBackend) GetDatabaseDdl(name string) (*databasepb.GetDatabaseDdlResponse, error)
- func (b *InMemoryBackend) GetIamPolicy(resource string, version int32) (*iampb.Policy, error)
- func (b *InMemoryBackend) GetInstance(name string) (*instancepb.Instance, error)
- func (b *InMemoryBackend) GetInstanceConfig(name string) (*instancepb.InstanceConfig, error)
- func (b *InMemoryBackend) ListDatabases(in *databasepb.ListDatabasesRequest) (*databasepb.ListDatabasesResponse, error)
- func (b *InMemoryBackend) ListInstanceConfigs(in *instancepb.ListInstanceConfigsRequest) (*instancepb.ListInstanceConfigsResponse, error)
- func (b *InMemoryBackend) ListInstances(in *instancepb.ListInstancesRequest) (*instancepb.ListInstancesResponse, error)
- func (b *InMemoryBackend) Reset()
- func (b *InMemoryBackend) Restore(ctx context.Context, data []byte) error
- func (b *InMemoryBackend) SetIamPolicy(in *iampb.SetIamPolicyRequest) (*iampb.Policy, error)
- func (b *InMemoryBackend) SetLauncher(l launcher)
- func (b *InMemoryBackend) Snapshot(ctx context.Context) []byte
- func (b *InMemoryBackend) TestIamPermissions(in *iampb.TestIamPermissionsRequest) (*iampb.TestIamPermissionsResponse, error)
- func (b *InMemoryBackend) UpdateDatabase(in *databasepb.UpdateDatabaseRequest) (*longrunningpb.Operation, error)
- func (b *InMemoryBackend) UpdateDatabaseDdl(ctx context.Context, in *databasepb.UpdateDatabaseDdlRequest) (*longrunningpb.Operation, error)
- func (b *InMemoryBackend) UpdateInstance(in *instancepb.UpdateInstanceRequest) (*longrunningpb.Operation, error)
- type Provider
- type Settings
Constants ¶
const ( // DefaultPort is the dedicated gRPC and REST listener's default TCP port. DefaultPort = 8135 // EngineAuto runs the Cloud Spanner emulator container when a container runtime is reachable. EngineAuto = "auto" // EngineNone never starts a container: instances and databases are metadata only. EngineNone = "none" // DefaultImage is the pinned Google Cloud Spanner emulator image. DefaultImage = "gcr.io/cloud-spanner-emulator/emulator:1.5.40" // DefaultStartupTimeout bounds how long the emulator may take to pull its image and accept calls. DefaultStartupTimeout = 5 * time.Minute )
Variables ¶
var ErrNilAppContext = errors.New("gcpspanner: nil app context")
ErrNilAppContext is returned when Init is called with a nil AppContext.
var ( ErrRuntimeUnavailable = errors.New("container runtime unavailable") )
Functions ¶
This section is empty.
Types ¶
type API ¶
type API struct {
Instances instancepb.InstanceAdminServer
Databases databasepb.DatabaseAdminServer
}
API groups the Spanner admin services for in-process callers (dashboard proxy).
type ConfigProvider ¶
type ConfigProvider interface {
GetGCPSpannerSettings() Settings
}
ConfigProvider extracts Cloud Spanner configuration from the AppContext Config.
type Handler ¶
type Handler struct {
Backend *InMemoryBackend
Port int
// contains filtered or unexported fields
}
Handler serves the Cloud Spanner instance and database admin APIs and, through the emulator, the data plane on a dedicated gRPC and REST listener.
func NewHandler ¶
func NewHandler(backend *InMemoryBackend) *Handler
NewHandler creates a Handler; callers override Port from Settings.
func (*Handler) ExtractOperation ¶
ExtractOperation is unused: requests never reach the shared router.
func (*Handler) ExtractResource ¶
ExtractResource is unused: requests never reach the shared router.
func (*Handler) GetSupportedOperations ¶
GetSupportedOperations lists the operations the backend answers itself; every other Spanner and DatabaseAdmin method is proxied to the emulator.
func (*Handler) Handler ¶
func (h *Handler) Handler() echo.HandlerFunc
Handler returns a 404 handler; the real API is on the dedicated port.
func (*Handler) MatchPriority ¶
MatchPriority is irrelevant because RouteMatcher never matches.
func (*Handler) RouteMatcher ¶
RouteMatcher never matches: Cloud Spanner runs on its own listener.
func (*Handler) Shutdown ¶
Shutdown stops the listener and the emulator, forcing a close after a short grace period.
type InMemoryBackend ¶
type InMemoryBackend struct {
// contains filtered or unexported fields
}
InMemoryBackend holds all Cloud Spanner admin state under one lock. The data plane lives in the emulator.
func NewInMemoryBackend ¶
func NewInMemoryBackend() *InMemoryBackend
NewInMemoryBackend creates an empty backend with no data plane; see SetLauncher.
func (*InMemoryBackend) Close ¶
func (b *InMemoryBackend) Close()
Close stops the emulator and waits for background work.
func (*InMemoryBackend) CreateDatabase ¶
func (b *InMemoryBackend) CreateDatabase( ctx context.Context, in *databasepb.CreateDatabaseRequest, ) (*longrunningpb.Operation, error)
CreateDatabase creates a database, executing its DDL in the emulator when one is available.
func (*InMemoryBackend) CreateInstance ¶
func (b *InMemoryBackend) CreateInstance(in *instancepb.CreateInstanceRequest) (*longrunningpb.Operation, error)
CreateInstance starts creating an instance; the operation completes once the data plane has it too.
func (*InMemoryBackend) DeleteInstance ¶
func (b *InMemoryBackend) DeleteInstance(name string) (*emptypb.Empty, error)
DeleteInstance deletes an instance together with its databases.
func (*InMemoryBackend) DropDatabase ¶
DropDatabase deletes a database unless drop protection is on.
func (*InMemoryBackend) GetDatabase ¶
func (b *InMemoryBackend) GetDatabase(name string) (*databasepb.Database, error)
GetDatabase returns a database.
func (*InMemoryBackend) GetDatabaseDdl ¶
func (b *InMemoryBackend) GetDatabaseDdl(name string) (*databasepb.GetDatabaseDdlResponse, error)
GetDatabaseDdl returns the DDL statements of a database.
func (*InMemoryBackend) GetIamPolicy ¶
GetIamPolicy returns the policy of an instance at the requested version.
func (*InMemoryBackend) GetInstance ¶
func (b *InMemoryBackend) GetInstance(name string) (*instancepb.Instance, error)
GetInstance returns an instance.
func (*InMemoryBackend) GetInstanceConfig ¶
func (b *InMemoryBackend) GetInstanceConfig(name string) (*instancepb.InstanceConfig, error)
GetInstanceConfig returns one configuration.
func (*InMemoryBackend) ListDatabases ¶
func (b *InMemoryBackend) ListDatabases( in *databasepb.ListDatabasesRequest, ) (*databasepb.ListDatabasesResponse, error)
ListDatabases lists the databases of an instance.
func (*InMemoryBackend) ListInstanceConfigs ¶
func (b *InMemoryBackend) ListInstanceConfigs( in *instancepb.ListInstanceConfigsRequest, ) (*instancepb.ListInstanceConfigsResponse, error)
ListInstanceConfigs lists the Google-managed configurations of a project.
func (*InMemoryBackend) ListInstances ¶
func (b *InMemoryBackend) ListInstances( in *instancepb.ListInstancesRequest, ) (*instancepb.ListInstancesResponse, error)
ListInstances lists the instances of a project.
func (*InMemoryBackend) Reset ¶
func (b *InMemoryBackend) Reset()
Reset stops the emulator and clears all state.
func (*InMemoryBackend) Restore ¶
func (b *InMemoryBackend) Restore(ctx context.Context, data []byte) error
Restore loads a snapshot. Instances caught mid-creation are dropped; the emulator starts empty on first use and is rebuilt from the restored schema.
func (*InMemoryBackend) SetIamPolicy ¶
func (b *InMemoryBackend) SetIamPolicy(in *iampb.SetIamPolicyRequest) (*iampb.Policy, error)
SetIamPolicy replaces the policy of an instance; a stale etag aborts the call.
func (*InMemoryBackend) SetLauncher ¶
func (b *InMemoryBackend) SetLauncher(l launcher)
SetLauncher connects the data plane to an emulator launcher; nil leaves the backend metadata only.
func (*InMemoryBackend) Snapshot ¶
func (b *InMemoryBackend) Snapshot(ctx context.Context) []byte
Snapshot serialises instances, policies, databases and their DDL. Table data lives in the emulator and is not persisted: it is lost on restart, while the schema is replayed into a fresh emulator.
func (*InMemoryBackend) TestIamPermissions ¶
func (b *InMemoryBackend) TestIamPermissions( in *iampb.TestIamPermissionsRequest, ) (*iampb.TestIamPermissionsResponse, error)
TestIamPermissions reports the requested Spanner permissions as granted: the emulator authorises all callers.
func (*InMemoryBackend) UpdateDatabase ¶
func (b *InMemoryBackend) UpdateDatabase(in *databasepb.UpdateDatabaseRequest) (*longrunningpb.Operation, error)
UpdateDatabase updates enable_drop_protection, the only mutable database field.
func (*InMemoryBackend) UpdateDatabaseDdl ¶
func (b *InMemoryBackend) UpdateDatabaseDdl( ctx context.Context, in *databasepb.UpdateDatabaseDdlRequest, ) (*longrunningpb.Operation, error)
UpdateDatabaseDdl applies DDL statements, in the emulator when one is available.
func (*InMemoryBackend) UpdateInstance ¶
func (b *InMemoryBackend) UpdateInstance(in *instancepb.UpdateInstanceRequest) (*longrunningpb.Operation, error)
UpdateInstance applies the masked fields of the instance.
type Provider ¶
type Provider struct{}
Provider implements service.Provider for Google Cloud Spanner. It serves gRPC and REST on its own listener (see Handler.StartWorker) and never matches on the shared AWS router.
func (*Provider) Init ¶
func (p *Provider) Init(ctx *service.AppContext) (service.Registerable, error)
Init creates the backend and handler; the port is bound in StartWorker.
type Settings ¶
type Settings struct {
Engine string `` //nolint:lll // config struct tags are intentionally verbose
/* 267-byte string literal not displayed */
Image string `` //nolint:lll // config struct tags are intentionally verbose
/* 228-byte string literal not displayed */
Port int `` //nolint:lll // config struct tags are intentionally verbose
/* 265-byte string literal not displayed */
StartupTimeout time.Duration `` //nolint:lll // config struct tags are intentionally verbose
/* 235-byte string literal not displayed */
}
Settings holds service-level configuration, embedded in the root CLI command as CLI.GCPSpanner.
func DefaultSettings ¶
func DefaultSettings() Settings
DefaultSettings returns the settings used when no ConfigProvider is available.