gcpmetadata

package module
v0.0.0-...-f3d6c89 Latest Latest
Warning

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

Go to latest
Published: May 22, 2020 License: MIT Imports: 7 Imported by: 3

README

https://github.com/sinmetal/gcpbox にお引越し

gcpmetadata

GCPのmetadata周りを扱うutility

GCP上では Metadata Server を参照し、Localでは環境変数を利用し、設定値を取得する。 GCPとLocalで同じロジックを使いつつ、設定値を持ち回るために作成した

動作確認した環境

  • Google App Engine Standard for Go 1.11
  • Google Compute Engine
  • Google Kubernetes Engine

Documentation

Index

Constants

View Source
const AppEngineDeploymentID = "GAE_DEPLOYMENT_ID"
View Source
const AppEngineEnv = "GAE_ENV"
View Source
const AppEngineInstance = "GAE_INSTANCE"
View Source
const AppEngineMemoryMB = "GAE_MEMORY_MB"
View Source
const AppEngineRuntime = "GAE_RUNTIME"
View Source
const AppEngineService = "GAE_SERVICE"
View Source
const AppEngineVersion = "GAE_VERSION"

Variables

This section is empty.

Functions

func ExtractionRegion

func ExtractionRegion(metaZone string) (string, error)

ExtractionRegion is Metadata Serverから取得する projects/[NUMERIC_PROJECT_ID]/zones/[ZONE] 形式の文字列から、Region部分を取り出す

func ExtractionZone

func ExtractionZone(metaZone string) (string, error)

ExtractionZone is Metadata Serverから取得する projects/[NUMERIC_PROJECT_ID]/zones/[ZONE] 形式の文字列から、Zone部分を取り出す

func GetAppEngineDeploymentID

func GetAppEngineDeploymentID() (string, error)

GetAppEngineDeploymentID is return deployment id The ID of the current deployment. https://cloud.google.com/appengine/docs/standard/go/runtime#environment_variables

func GetAppEngineEnv

func GetAppEngineEnv() (string, error)

GetAppEngineEnv is return env The App Engine environment. Set to standard. https://cloud.google.com/appengine/docs/standard/go/runtime#environment_variables

func GetAppEngineInstance

func GetAppEngineInstance() (string, error)

GetAppEngineInstance is return version id The ID of the instance on which your service is currently running. https://cloud.google.com/appengine/docs/standard/go/runtime#environment_variables

func GetAppEngineMemoryMB

func GetAppEngineMemoryMB() (string, error)

GetAppEngineMemoryMB is return MemoryMB The amount of memory available to the application process, in MB. https://cloud.google.com/appengine/docs/standard/go/runtime#environment_variables

func GetAppEngineRuntime

func GetAppEngineRuntime() (string, error)

GetAppEngineRuntime is return runtime The runtime specified in your app.yaml file. https://cloud.google.com/appengine/docs/standard/go/runtime#environment_variables

func GetAppEngineService

func GetAppEngineService() (string, error)

GetAppEngineService is return service id The service name specified in your app.yaml file. If no service name is specified, it is set to default. https://cloud.google.com/appengine/docs/standard/go/runtime#environment_variables

func GetAppEngineVersion

func GetAppEngineVersion() (string, error)

GetAppEngineVersion is return version id The current version label of your service. https://cloud.google.com/appengine/docs/standard/go/runtime#environment_variables

func GetInstanceAttribute

func GetInstanceAttribute(key string) (string, error)

GetInstanceAttribute is Instance Metadataを取得する GCP以外で動いている時は、環境変数を取得する

func GetProjectAttribute

func GetProjectAttribute(key string) (string, error)

GetProjectAttribute is Project Metadataを取得する GCP以外で動いている時は、環境変数を取得する

func GetProjectID

func GetProjectID() (string, error)

GetProjectID is Return current GCP ProjectID GCP上で動いている場合は、Project Metadataから取得し、そうでなければ、環境変数から取得する

func GetRegion

func GetRegion() (string, error)

GetRegion is Appが動いているRegionを取得する

func GetServiceAccountEmail

func GetServiceAccountEmail() (string, error)

GetServiceAccountEmail is Return current Service Account Email GCP上で動いている場合は、Metadataから取得し、そうでなければ、環境変数から取得する

func GetZone

func GetZone() (string, error)

GetZone is Appが動いているZoneを取得する

func Is

func Is(err error, code ErrCode) bool

func OnGCP

func OnGCP() bool

OnGCP is GCP上で動いているかどうかを返す GCP上と判断されるか確認したのは以下 Google App Engine Standard for Go 1.11 Google Compute Engine Google Kubernetes Engine

Types

type ErrCode

type ErrCode int
const (
	ErrUnknownCode ErrCode = iota
	ErrNotFoundCode
	ErrInvalidArgumentCode
)

type Error

type Error interface {
	Code() ErrCode
	error
}

func ErrInvalidArgument

func ErrInvalidArgument(expected string, argument string) Error

func ErrNotFound

func ErrNotFound(msg string) Error

Jump to

Keyboard shortcuts

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