mdl

package
v0.57.0 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PlaceholderAppEnv  = "app.env"
	PlaceholderAppName = "app.name"
	PlaceholderAppTags = "app.tags."
)

Placeholder constants for ModelId patterns.

View Source
const ConfigKeyModelIdDomainPattern = "app.model_id.domain_pattern"

ConfigKeyModelIdDomainPattern is the config key for the required model id domain pattern.

View Source
const NamedView = "named"

Variables

This section is empty.

Functions

func Box

func Box[T any](v T) *T

func Empty

func Empty[T any]() (out T)

func EmptyIfNil

func EmptyIfNil[T any](v *T) T

func FirstNonEmpty added in v0.40.4

func FirstNonEmpty[T comparable](values ...T) T

func IsEmpty added in v0.40.4

func IsEmpty[T comparable](in T) bool

func IsNil

func IsNil(m any) bool

func IsNilOrEmpty

func IsNilOrEmpty[T comparable](in *T) bool

func NamedOutput

func NamedOutput(in any) any

func NilIfEmpty

func NilIfEmpty[T comparable](in T) *T

func Unbox

func Unbox[T any](v *T, def T) T

func UnboxWith

func UnboxWith[T any](v *T, mkDef func() T) T

func UuidWithDashes

func UuidWithDashes(uuid *string) (*string, error)

Types

type ConfigProvider

type ConfigProvider interface {
	Get(key string, optionalDefault ...any) (any, error)
	GetString(key string, optionalDefault ...string) (string, error)
	GetStringMap(key string, optionalDefault ...map[string]any) (map[string]any, error)
}

ConfigProvider is an interface for reading config values. It is implemented by cfg.Config.

type Identifiable

type Identifiable interface {
	GetId() *uint
}

type Identifier

type Identifier struct {
	Id *uint `json:"id" binding:"required"`
}

func WithIdentifier

func WithIdentifier(id *uint) *Identifier

func (*Identifier) GetId

func (i *Identifier) GetId() *uint

type Keyed

type Keyed interface {
	GetKey() string
}

type ModelId

type ModelId struct {
	// Name is the model's name (the {modelId} placeholder)
	Name string `cfg:"name"`
	// Env is the environment (the {app.env} placeholder)
	Env string `cfg:"env"`
	// Application is the application name (the {app.name} placeholder)
	Application string `cfg:"application"`
	// Tags holds dynamic tag values (for {app.tags.<key>} placeholders)
	Tags map[string]string `cfg:"tags"`

	// DomainPattern is the formatting pattern read from config during PadFromConfig.
	DomainPattern string
}

ModelId represents the identity of a model using dynamic tags.

Unlike the legacy fixed-field ModelId (Project/Family/Group/etc), this version uses a dynamic tags map that can hold any key-value pairs.

The canonical string form is determined by the app.model_id.domain_pattern config key. Call PadFromConfig() once to populate fields from config (including the domain pattern), then use String() to obtain the canonical string representation.

func ParseModelId added in v0.56.0

func ParseModelId(config ConfigProvider, s string) (ModelId, error)

ParseModelId parses a string into a ModelId using the required domain pattern from config. This is the only supported way to parse a canonical model id string.

Returns an error if:

  • the domain pattern is not configured or invalid
  • the string doesn't match the expected domain pattern structure

func (ModelId) DomainString added in v0.56.0

func (m ModelId) DomainString() string

DomainString returns the canonical domain string representation of the ModelId (without the model name).

This method requires that the DomainPattern has been set via PadFromConfig. If no DomainPattern is set, DomainString returns an error.

Returns an error if:

  • the DomainPattern is not set (call PadFromConfig first)
  • the DomainPattern references fields/tags that are missing from the ModelId

func (*ModelId) PadFromConfig

func (m *ModelId) PadFromConfig(config ConfigProvider) error

PadFromConfig fills in empty fields of ModelId from config.

This method reads:

  • app.env -> Env (if empty)
  • app.name -> Application (if empty)
  • app.tags.* -> Tags (merged, existing tags take precedence)
  • app.model_id.domain_pattern -> DomainPattern (if empty and available)

The DomainPattern is read if available, enabling String() to work afterward. If the domain pattern config key is missing, the DomainPattern field is left empty, and String() will return an error when called.

All identity fields (env, app, tags) are optional. If a config key is not found, the corresponding field is left unchanged. This allows patterns to determine what's required (enforced at format time).

After loading the domain pattern, this method validates that all {app.tags.<key>} placeholders referenced in the pattern have corresponding entries in the merged Tags map. This prevents formatDomain from silently replacing missing tags with empty strings, which would produce malformed canonical IDs.

func (ModelId) String

func (m ModelId) String() string

String returns the canonical string representation of the ModelId.

This method requires that the DomainPattern has been set via PadFromConfig. If no DomainPattern is set, String returns an error.

Returns an error if:

  • the DomainPattern is not set (call PadFromConfig first)
  • the DomainPattern references fields/tags that are missing from the ModelId

func (ModelId) ToMap added in v0.56.0

func (i ModelId) ToMap() map[string]string

type Nameable

type Nameable interface {
	Identifiable
	GetName() *string
}

type NamedOutputV0

type NamedOutputV0 struct {
	Id   *uint   `json:"id"`
	Name *string `json:"name"`
}

type Resource

type Resource interface {
	GetResourceName() string
}

type ResourceContextAware

type ResourceContextAware interface {
	GetResourceContext() map[string]any
}

type Transformer

type Transformer func(in any) (out any)

type TransformerMap

type TransformerMap map[string]map[int]Transformer

type TransformerResolver

type TransformerResolver func(view string, version int, in any) (out any)

func Transform

func Transform(transformers TransformerMap) TransformerResolver

Jump to

Keyboard shortcuts

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