helpers

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: May 9, 2024 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	CycloneDXFields = RequiredTag("cyclonedx")
)
View Source
var (
	// OptionalJSONTag uses field names defined in json tags, if available
	OptionalJSONTag = TrimOmitempty(OptionalTag("json"))
)

Functions

func Decode

func Decode(typ reflect.Type, values map[string]string, prefix string, fn FieldName) interface{}

Decode based on the given type, applies all values to hydrate a new instance

func DecodeInto

func DecodeInto(obj interface{}, values map[string]string, prefix string, fn FieldName)

DecodeInto decodes all values to hydrate the given object instance

func DeriveBomRef

func DeriveBomRef(p pkg.Package) string

func Encode

func Encode(obj interface{}, prefix string, fn FieldName) map[string]string

Encode recursively encodes the object's properties as an ordered set of NameValue pairs

func EncodeComponent

func EncodeComponent(p pkg.Package) cyclonedx.Component

func EncodeProperties

func EncodeProperties(obj interface{}, prefix string) (out []cyclonedx.Property)

func PtrToStruct

func PtrToStruct(ptr interface{}) interface{}

func ToSyftModel

func ToSyftModel(bom *cyclonedx.BOM) (*sbom.SBOM, error)

Types

type FieldName

type FieldName func(field reflect.StructField) (string, bool)

FieldName return a flag to indicate this is a valid field and a name to use

func OptionalTag

func OptionalTag(tag string) FieldName

OptionalTag given a tag name, will return the defined tag or fall back to lower camel case field name

func RequiredTag

func RequiredTag(tag string) FieldName

RequiredTag based on the given tag, only use a field if present

func TrimOmitempty

func TrimOmitempty(fn FieldName) FieldName

TrimOmitempty trims `,omitempty` from the name

type NameValue

type NameValue struct {
	Name  string
	Value string
}

NameValue a simple type to store stringified name/value pairs

func Sorted

func Sorted(values map[string]string) (out []NameValue)

Sorted returns a sorted set of NameValue pairs

Jump to

Keyboard shortcuts

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