go/pkg/plugin/manifest.go
Snider ef5c83c04e refactor: delete pkg/io, slim pkg/log to go-io/go-log re-exports
- Delete pkg/io/ entirely (all consumers now use go-io)
- Delete pkg/log/{errors.go,log.go} duplicates (now in go-log)
- Rewrite pkg/log/log.go as thin re-export layer over go-log
- Keep pkg/log/{service.go,rotation.go} (framework/go-io deps)
- Swap internal pkg/ imports to go-io/go-log across ~30 files

Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-06 12:23:52 +00:00

50 lines
1.5 KiB
Go

package plugin
import (
"encoding/json"
coreerr "forge.lthn.ai/core/go-log"
"forge.lthn.ai/core/go-io"
)
// Manifest represents a plugin.json manifest file.
// Each plugin repository must contain a plugin.json at its root.
type Manifest struct {
Name string `json:"name"`
Version string `json:"version"`
Description string `json:"description"`
Author string `json:"author"`
Entrypoint string `json:"entrypoint"`
Dependencies []string `json:"dependencies,omitempty"`
MinVersion string `json:"min_version,omitempty"`
}
// LoadManifest reads and parses a plugin.json file from the given path.
func LoadManifest(m io.Medium, path string) (*Manifest, error) {
content, err := m.Read(path)
if err != nil {
return nil, coreerr.E("plugin.LoadManifest", "failed to read manifest", err)
}
var manifest Manifest
if err := json.Unmarshal([]byte(content), &manifest); err != nil {
return nil, coreerr.E("plugin.LoadManifest", "failed to parse manifest JSON", err)
}
return &manifest, nil
}
// Validate checks the manifest for required fields.
// Returns an error if name, version, or entrypoint are missing.
func (m *Manifest) Validate() error {
if m.Name == "" {
return coreerr.E("plugin.Manifest.Validate", "name is required", nil)
}
if m.Version == "" {
return coreerr.E("plugin.Manifest.Validate", "version is required", nil)
}
if m.Entrypoint == "" {
return coreerr.E("plugin.Manifest.Validate", "entrypoint is required", nil)
}
return nil
}