jx/internal/resource/resource.go

55 lines
910 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-25 20:31:06 +00:00
"context"
_ "encoding/json"
2024-03-25 20:31:06 +00:00
_ "fmt"
_ "gopkg.in/yaml.v3"
_ "net/url"
2024-03-20 16:15:27 +00:00
)
type Resource interface {
2024-03-25 20:31:06 +00:00
Type() string
URI() string
//SetURI(string) error
ResolveId(context.Context) string
ResourceLoader
StateTransformer
ResourceReader
2024-04-09 19:30:05 +00:00
ResourceValidator
2024-03-20 16:15:27 +00:00
}
2024-03-20 19:23:31 +00:00
type ResourceValidator interface {
2024-03-25 20:31:06 +00:00
Validate() error
2024-03-20 16:15:27 +00:00
}
type ResourceCreator interface {
2024-03-25 20:31:06 +00:00
Create(context.Context) error
2024-03-20 16:15:27 +00:00
}
type ResourceReader interface {
2024-03-25 20:31:06 +00:00
Read(context.Context) ([]byte, error)
2024-03-20 16:15:27 +00:00
}
type ResourceUpdater interface {
2024-03-25 20:31:06 +00:00
Update() error
2024-03-20 16:15:27 +00:00
}
type ResourceDeleter interface {
2024-03-25 20:31:06 +00:00
Delete() error
2024-03-20 16:15:27 +00:00
}
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 {
2024-03-25 20:31:06 +00:00
r, e := ResourceTypes.New(uri)
if e == nil {
return r
}
return nil
2024-03-20 16:15:27 +00:00
}