Documentation
¶
Index ¶
- func AddConfigFile(path string) error
- func CloneConfig[T Brick](liveID ...string) (newLiveID string)
- func Get[T Brick](liveID ...string) T
- func GetOrCreate[T Brick](liveID ...string) T
- func RandomLiveID() string
- func Register[T Brick]()
- func RegisterLiveIDType[T Brick](liveID string)
- func RegisterLives[T BrickLives]()
- func RegisterNewer[T BrickNewer]()
- func SetLiveIDConstraint(constraint bool)
- type Brick
- type BrickConfig
- type BrickFileConfig
- type BrickLives
- type BrickManager
- type BrickNewer
- type Live
- type RegisterBrickParam
- type TypeLives
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddConfigFile ¶
AddConfigFile adds brick configurations from a file, supporting JSON and YAML formats.
func CloneConfig ¶
func Get ¶
Get retrieves a brick instance, creating it if necessary. If liveID is not provided, it will use the typeID as the LiveID.
If an instance for the given liveID has never been created before, and this is an unknown liveID, the function will panic to prevent unexpected behavior. An unknown liveID is one that has not been declared in the configuration or tag, and has not been explicitly registered as a non-default liveID. The default instance's liveID is the same as the typeID.
When retrieving a non-pointer Brick instance, be aware of whether the type can be copied safely. No checks are performed for this.
func GetOrCreate ¶
GetOrCreate like Get, but it will create a new instance for unknown liveID.
func RandomLiveID ¶
func RandomLiveID() string
func Register ¶
func Register[T Brick]()
Register registers the brick type and recursively registers its all dependencies. It uses the BrickTypeID method of the provided type to determine the type ID. This method is used for bricks that do not require custom configuration parsing.
func RegisterLiveIDType ¶
RegisterLiveIDType registers the type of the liveID instance, allowing the actual type of liveID to be obtained when injecting a brick for an interface.
func RegisterLives ¶
func RegisterLives[T BrickLives]()
RegisterLives like RegisterNewer, but it requires the brick to implement the BrickLives interface, which describes the specified instance's specified dependency relationship.
func RegisterNewer ¶
func RegisterNewer[T BrickNewer]()
RegisterNewer like Register, but it also registers a factory for configuration parsing. The provided type must implement the BrickNewer interface, which includes the NewBrick method for parsing configurations.
func SetLiveIDConstraint ¶
func SetLiveIDConstraint(constraint bool)
SetLiveIDConstraint sets the constraint that all instances of the same brick type must have one liveID set to typeID.
Types ¶
type Brick ¶
type Brick interface {
// BrickTypeID returns a unique constant string for each brick type.
BrickTypeID() string
}
Brick is the interface that all bricks must implement.
type BrickConfig ¶
type BrickConfig struct {
TypeID string
LiveID string
Config any
// contains filtered or unexported fields
}
BrickConfig holds the configuration for a single brick instance.
type BrickFileConfig ¶
type BrickFileConfig struct {
MetaData struct {
Name string `json:"name" yaml:"name" toml:"name"`
TypeID string `json:"typeID" yaml:"typeID" toml:"typeID"`
NoCheck bool `json:"noCheck" yaml:"noCheck" toml:"noCheck"`
} `json:"metaData" yaml:"metaData" toml:"metaData"`
Lives []struct {
LiveID string `json:"liveID" yaml:"liveID" toml:"liveID"`
Config any `json:"config" yaml:"config" toml:"config"`
} `json:"lives" yaml:"lives" toml:"lives"`
}
BrickFileConfig defines the structure of a brick configuration file.
type BrickLives ¶
type BrickLives interface {
BrickNewer
// Used when multiple different instances of a type depend on different instances of the same type.
// The dependency relationship returned here will forcibly override the dependency relationship in the tag.
BrickLives() []Live
}
type BrickManager ¶
type BrickManager struct {
// contains filtered or unexported fields
}
BrickManager manages brick configurations and instances.
func (*BrickManager) AddConfigFile ¶
func (b *BrickManager) AddConfigFile(path string) error
AddConfigFile adds brick configurations from a file, supporting JSON and YAML formats.
func (*BrickManager) RegisterLiveIDType ¶
func (b *BrickManager) RegisterLiveIDType(liveID string, reflectType reflect.Type)
type BrickNewer ¶
type BrickNewer interface {
Brick
// NewBrick parses the configuration and returns a new instance of the brick.
// If the configuration file does not provide the configuration for the component, jsonConfig is nil.
//
// To ensure that this method can be called even if receiver is nil, please create a new instance and return it.
NewBrick(jsonConfig []byte) Brick
}