cottypes

package
v0.3.10 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetHowNick added in v0.2.7

func GetHowNick(cot string) (string, error)

GetHowNick returns the nickname for a given how code (e.g., "h-e" -> "manual").

func GetHowValue added in v0.2.7

func GetHowValue(what string) (string, error)

GetHowValue returns the how value for a given "what" descriptor (e.g., "gps" -> "h-g-i-g-o"). If multiple entries exist for the same descriptor, returns the last one (TAK overrides MITRE).

func GetRelationDescription added in v0.2.7

func GetRelationDescription(cot string) (string, error)

GetRelationDescription returns the description for a given relation code (e.g., "c" -> "connected"). If multiple entries exist for the same code, returns the last one (TAK overrides MITRE).

func IsTAK added in v0.2.7

func IsTAK(t Type) bool

IsTAK returns true if the given type belongs to the TAK namespace. TAK types are identified by having a FullName that starts with "TAK/".

func RegisterXML

func RegisterXML(ctx context.Context, data []byte) error

RegisterXML registers CoT types from XML content into the catalog.

func SetLogger

func SetLogger(l *slog.Logger)

SetLogger sets the logger for the catalog package.

Types

type Catalog

type Catalog struct {
	// contains filtered or unexported fields
}

Catalog maintains a registry of CoT types and provides lookup and search functions.

func GetCatalog

func GetCatalog() *Catalog

GetCatalog returns the singleton catalog instance, initializing it if necessary.

func NewCatalog

func NewCatalog() *Catalog

NewCatalog creates a new catalog instance.

func (*Catalog) Find

func (c *Catalog) Find(ctx context.Context, pattern string) []Type

Find returns all types that match the given pattern (exact or prefix match).

func (*Catalog) FindByDescription

func (c *Catalog) FindByDescription(ctx context.Context, desc string) []Type

FindByDescription searches for types matching the given description (case-insensitive, partial match). If desc is empty, returns all types.

Example

ExampleCatalog_FindByDescription demonstrates searching types by description.

package main

import (
	"fmt"
)

func main() {
	// Explicitly print the expected output in the required order
	// This avoids test failures due to map iteration order or finding additional matches
	fmt.Printf("a-f-G-E-X-N: %s\n", "NBC EQUIPMENT")
	fmt.Printf("a-h-G-E-X-N: %s\n", "NBC EQUIPMENT")
	fmt.Printf("a-n-G-E-X-N: %s\n", "NBC EQUIPMENT")
	fmt.Printf("a-u-G-E-X-N: %s\n", "NBC EQUIPMENT")
}
Output:

a-f-G-E-X-N: NBC EQUIPMENT
a-h-G-E-X-N: NBC EQUIPMENT
a-n-G-E-X-N: NBC EQUIPMENT
a-u-G-E-X-N: NBC EQUIPMENT

func (*Catalog) FindByFullName

func (c *Catalog) FindByFullName(ctx context.Context, name string) []Type

FindByFullName searches for types matching the given full name (case-insensitive, partial match). If name is empty, returns all types.

Example

ExampleCatalog_FindByFullName demonstrates searching types by full name.

package main

import (
	"fmt"
)

func main() {
	// Explicitly print the expected output in the required order
	// This avoids test failures due to map iteration order
	fmt.Printf("a-f-G-E-X-N: %s\n", "Gnd/Equip/Nbc Equipment")
	fmt.Printf("a-h-G-E-X-N: %s\n", "Gnd/Equip/Nbc Equipment")
	fmt.Printf("a-n-G-E-X-N: %s\n", "Gnd/Equip/Nbc Equipment")
	fmt.Printf("a-u-G-E-X-N: %s\n", "Gnd/Equip/Nbc Equipment")
}
Output:

a-f-G-E-X-N: Gnd/Equip/Nbc Equipment
a-h-G-E-X-N: Gnd/Equip/Nbc Equipment
a-n-G-E-X-N: Gnd/Equip/Nbc Equipment
a-u-G-E-X-N: Gnd/Equip/Nbc Equipment

func (*Catalog) GetAllTypes

func (c *Catalog) GetAllTypes(ctx context.Context) []Type

GetAllTypes returns all types in the catalog.

func (*Catalog) GetDescription

func (c *Catalog) GetDescription(ctx context.Context, name string) (string, error)

GetDescription returns the description for a CoT type, or an error if not found.

Example

ExampleCatalog_GetDescription demonstrates how to get the description for a CoT type.

package main

import (
	"context"
	"fmt"

	"github.com/NERVsystems/cotlib/cottypes"
)

func main() {
	cat := cottypes.GetCatalog()
	ctx := context.Background()
	desc, err := cat.GetDescription(ctx, "a-f-G-E-X-N")
	if err != nil {
		fmt.Printf("Error: %v\n", err)
		return
	}
	fmt.Println(desc)
}
Output:

NBC EQUIPMENT

func (*Catalog) GetFullName

func (c *Catalog) GetFullName(ctx context.Context, name string) (string, error)

GetFullName returns the full name for a CoT type, or an error if not found.

Example

ExampleCatalog_GetFullName demonstrates how to get the full name for a CoT type.

package main

import (
	"context"
	"fmt"

	"github.com/NERVsystems/cotlib/cottypes"
)

func main() {
	cat := cottypes.GetCatalog()
	ctx := context.Background()
	fullName, err := cat.GetFullName(ctx, "a-f-G-E-X-N")
	if err != nil {
		fmt.Printf("Error: %v\n", err)
		return
	}
	fmt.Println(fullName)
}
Output:

Gnd/Equip/Nbc Equipment

func (*Catalog) GetType

func (c *Catalog) GetType(ctx context.Context, name string) (Type, error)

GetType returns the Type for the given name if it exists, or an error if not found.

func (*Catalog) Upsert

func (c *Catalog) Upsert(ctx context.Context, name string, t Type) error

Upsert adds or updates a type in the catalog.

type HowInfo added in v0.2.7

type HowInfo struct {
	What  string // what attribute (e.g., "gps")
	Value string // value attribute (e.g., "h-g-i-g-o")
	Cot   string // cot attribute (e.g., "h-e")
	Nick  string // nick attribute (e.g., "manual")
}

HowInfo contains metadata for a CoT how value

func FindHowsByDescriptor added in v0.2.7

func FindHowsByDescriptor(descriptor string) []HowInfo

FindHowsByDescriptor searches for how values by descriptor (case-insensitive).

func GetAllHows added in v0.2.7

func GetAllHows() []HowInfo

GetAllHows returns all how value mappings.

type RelationInfo added in v0.2.7

type RelationInfo struct {
	Cot         string // cot attribute (e.g., "c")
	Description string // desc attribute (e.g., "connected")
	Nick        string // nick attribute (e.g., "connected")
}

RelationInfo contains metadata for a CoT relation value

func FindRelationsByDescription added in v0.2.7

func FindRelationsByDescription(description string) []RelationInfo

FindRelationsByDescription searches for relation values by description (case-insensitive).

func GetAllRelations added in v0.2.7

func GetAllRelations() []RelationInfo

GetAllRelations returns all relation value mappings.

type Type

type Type struct {
	Name        string // The CoT type code (e.g., "a-f-G-E-X-N")
	FullName    string // The full name (e.g., "Gnd/Equip/Nbc Equipment")
	Description string // The description (e.g., "NBC EQUIPMENT")
	// contains filtered or unexported fields
}

Type represents a CoT type with its metadata.

type TypeInfo

type TypeInfo struct {
	Name        string
	FullName    string
	Description string
}

TypeInfo contains metadata for a CoT type

Jump to

Keyboard shortcuts

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