ecsmeta

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2020 License: MIT Imports: 11 Imported by: 0

README

ecsmeta

This is a utility module for getting ECS ​​metadata. Mainly used to embed ECS metadata in text/template (or http://github.com/kayac/go-config ).

See below for ECS metadata. https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-metadata-endpoint.html

This respects https://github.com/fujiwara/tfstate-lookup.

Usage (Go package)

See details in godoc.

package main

import (
	"log"
	"os"
	"strings"
	"text/template"

	"github.com/mashiike/ecsmeta"
)

func main() {
    const templateText = `Image: {{ecsmeta ".Containers[0].Image"}}`
	funcMap := ecsmeta.MustFuncMap()

	tmpl, err := template.New("txt").Funcs(funcMap).Parse(templateText)
	if err != nil {
		log.Fatalf("parsing: %s", err)
	}
	err = tmpl.Execute(os.Stdout, nil)
	if err != nil {
		log.Fatalf("execution: %s", err)
	}
}

LICENSE

Mozilla Public License Version 2.0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FuncMap

func FuncMap(opts ...Option) (template.FuncMap, error)

FuncMap provides a tamplate.FuncMap

func FuncMapWithName

func FuncMapWithName(name string, opts ...Option) (template.FuncMap, error)

FuncMapWithName provides a tamplate.FuncMap.

func MustFuncMap

func MustFuncMap(opts ...Option) template.FuncMap

MustFuncMap is similar to FuncMap, but panics if it cannot get ECS metadata.

func MustFuncMapWithName

func MustFuncMapWithName(name string, opts ...Option) template.FuncMap

MustFuncMapWithName is similar to FuncMapWithName, but panics if it cannot get ECS metadata.

Types

type Object

type Object struct {
	Value interface{}
}

Object is ECS metadata object

func New

func New(opts ...Option) *Object

New gets the ECS metadata. The acquisition method changes depending on the option. if return ECSMeta(nil), failed get ECS metadata

func (Object) Bytes

func (o Object) Bytes() []byte

Bytes returns a Byte array representing the metadata object

func (*Object) Query

func (o *Object) Query(query string) (*Object, error)

Query queries object by go-jq

func (Object) String

func (o Object) String() string

String returns a json string

type Option

type Option func(*setting)

Option provides a way to specify how to get the ECS metadata

func WithEnableV2

func WithEnableV2() Option

WithEnableV2 enables automatic detection of V2 endpoints.

func WithEndpoint

func WithEndpoint(endpoint string) Option

WithEndpoint specifies the Endpoint to get ECS metadata.

func WithHTTPClient

func WithHTTPClient(client *http.Client) Option

WithHTTPClient specifies the HTTP client used to download ECS Metadata.

func WithLogger

func WithLogger(l *log.Logger) Option

WithLogger specifies the output method of Log

func WithRetryPolicy

func WithRetryPolicy(policy backoff.Policy) Option

WithRetryPolicy specifies the retry policy when ECS metadata download fails.

Directories

Path Synopsis
cmd
ecsmeta-jq command

Jump to

Keyboard shortcuts

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