cottypes

package
v0.2.5 Latest Latest
Warning

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

Go to latest
Published: May 19, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterXML

func RegisterXML(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(logger *slog.Logger) *Catalog

NewCatalog creates a new catalog instance with the given logger.

func (*Catalog) Find

func (c *Catalog) Find(pattern string) []Type

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

func (*Catalog) FindByDescription

func (c *Catalog) FindByDescription(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(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() []Type

GetAllTypes returns all types in the catalog.

func (*Catalog) GetDescription

func (c *Catalog) GetDescription(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 (
	"fmt"

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

func main() {
	cat := cottypes.GetCatalog()
	desc, err := cat.GetDescription("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(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 (
	"fmt"

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

func main() {
	cat := cottypes.GetCatalog()
	fullName, err := cat.GetFullName("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(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(name string, t Type) error

Upsert adds or updates a type in the catalog.

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