Documentation
¶
Index ¶
- func CredentialsAndProjectIDFromEnv(gKeyEnvVarName, projectIDEnvVarName string) ([]option.ClientOption, string, error)
- func CredentialsOptionsFromEnv(envKey string) ([]option.ClientOption, error)
- func Decrypt(ctx context.Context, kmsClient *kms.KeyManagementClient, ...) ([]byte, error)
- func Encrypt(ctx context.Context, kmsClient *kms.KeyManagementClient, ...) ([]byte, error)
- func Err(err error) error
- func Errorf(format string, v ...interface{}) error
- func GetEnvVar(name, def string) string
- func InitLogging(ctx context.Context, projectID string, opts []option.ClientOption) (io.Closer, error)
- func Print(v ...interface{})
- func Printf(format string, v ...interface{})
- func Println(v ...interface{})
- func SetComponent(s string)
- func WithTrace(ctx context.Context, r *http.Request) context.Context
- type Entry
- type Fielder
- type GoogleJSON
- type Leveler
- type Line
- type Printer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CredentialsAndProjectIDFromEnv ¶ added in v0.0.4
func CredentialsAndProjectIDFromEnv(gKeyEnvVarName, projectIDEnvVarName string) ([]option.ClientOption, string, error)
CredentialsAndProjectIDFromEnv returns ClientOption's with credentials filled in and the project ID ProjectID returns the project ID by looking in several places in the following order of preference: * env var passed in via envVarName * set in GCE metadata with matching name to envVarName (user defined) * instance metadata * in credentials key/json
gKeyEnvVarName is required only if not running on GCP compute projectIDEnvVarName is optional
func CredentialsOptionsFromEnv ¶
func CredentialsOptionsFromEnv(envKey string) ([]option.ClientOption, error)
CredentialsOptionsFromEnv this will check an environment var with key you provide, which should contain your JSON credentials base64 encoded. Can passed returned value directly into clients. Run `base64 -w 0 account.json` to create this value. This also supports running on GCP, just don't set this environment variable or metadata on GCP. This will not error if it doesn't exist, so you can use this locally and let Google automatically get credentials when running on GCP.
func Decrypt ¶ added in v0.1.3
func Decrypt(ctx context.Context, kmsClient *kms.KeyManagementClient, projectID, region, keyRingName, keyName string, data []byte) ([]byte, error)
Decrypt using Google KMS to encrypt data keyName is just the last part of the default keyring we're using
func Encrypt ¶ added in v0.1.3
func Encrypt(ctx context.Context, kmsClient *kms.KeyManagementClient, projectID, region, keyRingName, keyName string, data []byte) ([]byte, error)
Encrypt using Google KMS to encrypt data keyName is just the last part of the default keyring we're using
func Err ¶ added in v0.0.23
Err will log an error (if it hasn't already been logged) and return the same error
func Errorf ¶ added in v0.0.23
Errorf will log an error (if it hasn't already been logged) and return an error as if fmt.Errorf was called
func GetEnvVar ¶
GetEnvVar def is default, leave blank to fatal if not found checks in env, then GCE metadata
func InitLogging ¶ added in v0.0.8
func InitLogging(ctx context.Context, projectID string, opts []option.ClientOption) (io.Closer, error)
InitLogging you must call this to initialize the logging and error reporting clients. Not required if using cloud run. Call defer x.Close() on the returned closer to ensure logs get flushed.
func Printf ¶ added in v0.0.16
func Printf(format string, v ...interface{})
Printf take a wild guess
func SetComponent ¶ added in v0.0.8
func SetComponent(s string)
SetComponent Stackdriver Log Viewer allows filtering and display of this as `jsonPayload.component`.
Types ¶
type Entry ¶ added in v0.0.8
type Entry struct { Message string `json:"message"` Severity string `json:"severity,omitempty"` Trace string `json:"logging.googleapis.com/trace,omitempty"` // Stackdriver Log Viewer allows filtering and display of this as `jsonPayload.component`. Component string `json:"component,omitempty"` Fields map[string]interface{} }
Entry defines a log entry.
type Fielder ¶ added in v0.0.8
type Fielder interface { // F adds structured key/value pairs which will show up nicely in Cloud Logging. // Typically use this on the same line as your Printx() F(string, interface{}) Line // With clones (unlike F), then adds structured key/value pairs which will show up nicely in Cloud Logging. // Use this one if you plan on passing this along to other functions or setting global fields. With(string, interface{}) Line WithTrace(r *http.Request) Line }
Fielder methods for adding structured fields
type GoogleJSON ¶ added in v0.0.4
type GoogleJSON struct { ProjectID string `json:"project_id"` Type string `json:"type"` ClientEmail string `json:"client_email"` }
GoogleJSON is the struct you get when you create a new service account
func AccountAndCredentialsFromEnv ¶ added in v0.0.6
func AccountAndCredentialsFromEnv(envKey string) (*GoogleJSON, []option.ClientOption, error)
AccountAndCredentialsFromEnv this will check an environment var with key you provide, which should contain your JSON credentials base64 encoded. Can passed returned value directly into clients. Run `base64 -w 0 account.json` to create this value. This also supports running on GCP, just don't set this environment variable or metadata on GCP. This will not error if it doesn't exist, so you can use this locally and let Google automatically get credentials when running on GCP.
type Leveler ¶ added in v0.0.16
type Leveler interface { // Debug returns a new logger with Debug severity Debug() Line // Info returns a new logger with INFO severity Info() Line // Error returns a new logger with ERROR severity Error() Line }
Leveler methods to set levels on loggers