runtimeconfigurator

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2018 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package runtimeconfigurator provides a runtimevar.Driver implementation that reads variables from GCP Cloud Runtime Configurator.

Construct a Client, then use NewVariable to construct any number of runtimevar.Variable objects.

Index

Examples

Constants

This section is empty.

Variables

Set is a Wire provider set that provides *Client using a default connection to the Runtime Configurator API given a GCP token source.

Functions

func Dial

Dial opens a gRPC connection to the Runtime Configurator API.

The second return value is a function that can be called to clean up the connection opened by Dial.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

A Client constructs runtime variables using the Runtime Configurator API.

func NewClient

func NewClient(stub pb.RuntimeConfigManagerClient) *Client

NewClient returns a new client that makes calls to the given gRPC stub.

Example
package main

import (
	"context"
	"log"

	"github.com/google/go-cloud/gcp"
	"github.com/google/go-cloud/runtimevar/runtimeconfigurator"
)

func main() {
	ctx := context.Background()
	creds, err := gcp.DefaultCredentials(ctx)
	if err != nil {
		log.Fatal(err)
	}
	stub, cleanup, err := runtimeconfigurator.Dial(ctx, creds.TokenSource)
	if err != nil {
		log.Fatal(err)
	}
	defer cleanup()
	client := runtimeconfigurator.NewClient(stub)

	// Now use the client.
	_ = client
}

func (*Client) NewVariable

func (c *Client) NewVariable(name ResourceName, decoder *runtimevar.Decoder, opts *Options) (*runtimevar.Variable, error)

NewVariable constructs a runtimevar.Variable object with this package as the driver implementation. Provide a decoder to unmarshal updated configurations into similar objects during the Watch call.

Example
package main

import (
	"context"
	"log"

	"github.com/google/go-cloud/runtimevar"
	"github.com/google/go-cloud/runtimevar/runtimeconfigurator"
)

func main() {
	// Assume client was created at server startup.
	ctx := context.Background()
	client := openClient()

	// MyAppConfig is an example unmarshaled type for configuration stored in key
	// "projects/projectID/configs/configName/variables/appConfig". Runtime
	// Configurator stores individual variables as strings or binary data, so a
	// decoder automatically parses the data.
	type MyAppConfig struct {
		MsgOfTheDay string `json:"msg_of_the_day"`
	}
	decoder := runtimevar.NewDecoder(&MyAppConfig{}, runtimevar.JSONDecode)

	// Fill these in with the values from the Cloud Console.
	name := runtimeconfigurator.ResourceName{
		ProjectID: "projectID",
		Config:    "configName",
		Variable:  "appConfig",
	}

	// Create a variable object to watch for changes.
	v, err := client.NewVariable(name, decoder, nil)
	if err != nil {
		log.Fatal(err)
	}
	defer v.Close()

	// Read the current value. Calling Watch() again will block until the value
	// changes.
	snapshot, err := v.Watch(ctx)
	if err != nil {
		log.Fatal(err)
	}

	// Value will always be of the decoder's type.
	cfg := snapshot.Value.(*MyAppConfig)
	log.Println(cfg.MsgOfTheDay)
}

func openClient() *runtimeconfigurator.Client {
	return nil
}

type Options added in v0.7.0

type Options struct {
	// WaitDuration controls how quickly Watch polls. Defaults to 30 seconds.
	WaitDuration time.Duration
}

Options sets options.

type ResourceName

type ResourceName struct {
	ProjectID string
	Config    string
	Variable  string
}

ResourceName identifies the full configuration variable path used by the service.

func (ResourceName) String

func (r ResourceName) String() string

String returns the full configuration variable path.

Jump to

Keyboard shortcuts

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