jx/internal/resource/resource.go

55 lines
913 B
Go
Raw Normal View History

2024-03-20 19:23:31 +00:00
// Copyright 2024 Matthew Rich <matthewrich.conf@gmail.com>. All rights reserved.
2024-03-22 17:39:06 +00:00
// The resource package handles CRUD operations on resources and YAML (de)serialization
2024-03-20 16:15:27 +00:00
package resource
import (
2024-03-20 19:23:31 +00:00
"context"
_ "fmt"
_ "gopkg.in/yaml.v3"
_ "net/url"
2024-03-20 16:15:27 +00:00
)
type Resource interface {
2024-03-20 19:23:31 +00:00
Type() string
URI() string
//SetURI(string) error
ResolveId(context.Context) string
2024-03-20 16:15:27 +00:00
ResourceLoader
StateTransformer
2024-03-20 19:23:31 +00:00
ResourceReader
2024-03-20 16:15:27 +00:00
}
2024-03-20 19:23:31 +00:00
// validate the type/uri
type ResourceValidator interface {
Validate() error
2024-03-20 16:15:27 +00:00
}
type ResourceCreator interface {
2024-03-20 19:23:31 +00:00
Create(context.Context) error
2024-03-20 16:15:27 +00:00
}
type ResourceReader interface {
2024-03-20 19:23:31 +00:00
Read(context.Context) ([]byte, error)
2024-03-20 16:15:27 +00:00
}
type ResourceUpdater interface {
Update() error
}
type ResourceDeleter interface {
Delete() error
}
2024-03-20 19:23:31 +00:00
type ResourceDecoder struct {
2024-03-20 16:15:27 +00:00
}
2024-03-20 19:23:31 +00:00
func NewResource(uri string) Resource {
r,e := ResourceTypes.New(uri)
if e == nil {
return r
}
return nil
2024-03-20 16:15:27 +00:00
}