metadatax

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

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

Go to latest
Published: Sep 10, 2024 License: MIT Imports: 9 Imported by: 10

README

license

metadatax is a Go library which provides a generic interface and various implementations to gather metadata from different environments.

Installation

go get github.com/gezacorp/metadatax

Usage

package main

import (
    "fmt"

    "github.com/gezacorp/metadatax"
)

func main() {
    meta := metadatax.New()
    meta.AddLabel("name", "test entity")
    meta.Segment("label").AddLabel("version", "0.0.1")
    meta.Segment("image").
        AddLabel("name", "nginx").
        AddLabel("hash", "sha256:b26544c7942a085ec5c8ebaa149e6015100b0906d5b395903b5b035f6d231d35")

    for _, label := range meta.GetLabelsSlice() {
        fmt.Printf("%s = %s\n", label.Name, label.Value)
    }
}

output

image:hash = sha256:b26544c7942a085ec5c8ebaa149e6015100b0906d5b395903b5b035f6d231d35
image:name = nginx
label:version = 0.0.1
name = test entity

Documentation

Index

Constants

This section is empty.

Variables

View Source
var PIDNotFoundError = errors.New("pid is not found in context")

Functions

func ContextWithPID

func ContextWithPID(ctx context.Context, pid int32) context.Context

func PIDFromContext

func PIDFromContext(ctx context.Context) (int32, bool)

func SendHTTPGetRequest

func SendHTTPGetRequest(ctx context.Context, httpClient HTTPClient, req *http.Request) ([]byte, error)

Types

type Collector

type Collector interface {
	GetMetadata(ctx context.Context) (MetadataContainer, error)
}

type CollectorCollection

type CollectorCollection interface {
	Collector

	Add(Collector)
	List() Collectors
	Clear()
}

func NewCollectorCollection

func NewCollectorCollection() CollectorCollection

type Collectors

type Collectors []Collector

type HTTPClient

type HTTPClient interface {
	Do(*http.Request) (*http.Response, error)
}

type Labels

type Labels map[string][]string

func ConvertMapStringToLabels

func ConvertMapStringToLabels(input map[string]string) Labels

type MetadataContainer

type MetadataContainer interface {
	MetadataLabels
}

func New

func New(opts ...MetadataOption) MetadataContainer

type MetadataLabels

type MetadataLabels interface {
	GetLabels() Labels
	GetLabelsSlice() []SlicedLabel
	AddLabel(name string, value ...string) MetadataContainer
	AddLabels(Labels) MetadataContainer
	Segment(name string, opts ...MetadataOption) MetadataContainer
}

type MetadataOption

type MetadataOption func(*metadata)

func WithAllowEmptyValues

func WithAllowEmptyValues(enabled bool) MetadataOption

func WithConcurrencySupport

func WithConcurrencySupport() MetadataOption

func WithMetadata

func WithMetadata(md MetadataContainer) MetadataOption

func WithPrefix

func WithPrefix(prefix string) MetadataOption

func WithSegmentSeparator

func WithSegmentSeparator(separator string) MetadataOption

func WithStoreAtSegment

func WithStoreAtSegment(store bool) MetadataOption

func WithUniqueKeys

func WithUniqueKeys(enabled bool) MetadataOption

func WithUniqueValues

func WithUniqueValues(enabled bool) MetadataOption

type SlicedLabel

type SlicedLabel struct {
	Name  string
	Value string
}

Directories

Path Synopsis
collectors
azure Module
docker Module
ec2 Module
gcp Module
kubernetes Module
linuxos Module
procfs Module
sysfsdmi Module

Jump to

Keyboard shortcuts

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