69 lines
1.4 KiB
Go
69 lines
1.4 KiB
Go
// Copyright 2024 Matthew Rich <matthewrich.conf@gmail.com>. All rights reserved.
|
|
|
|
// The resource package handles CRUD operations on resources and YAML (de)serialization
|
|
package resource
|
|
|
|
import (
|
|
"context"
|
|
_ "encoding/json"
|
|
_ "fmt"
|
|
_ "gopkg.in/yaml.v3"
|
|
_ "net/url"
|
|
)
|
|
|
|
type ResourceSelector func(r *Declaration) bool
|
|
|
|
type Resource interface {
|
|
Type() string
|
|
URI() string
|
|
SetURI(string) error
|
|
ResolveId(context.Context) string
|
|
ResourceLoader
|
|
StateTransformer
|
|
ResourceReader
|
|
ResourceValidator
|
|
Clone() Resource
|
|
}
|
|
|
|
type ResourceValidator interface {
|
|
Validate() error
|
|
}
|
|
|
|
type ResourceCreator interface {
|
|
Create(context.Context) error
|
|
}
|
|
|
|
type ResourceReader interface {
|
|
Read(context.Context) ([]byte, error)
|
|
}
|
|
|
|
type ResourceUpdater interface {
|
|
Update() error
|
|
}
|
|
|
|
type ResourceDeleter interface {
|
|
Delete() error
|
|
}
|
|
|
|
type ResourceDecoder struct {
|
|
}
|
|
|
|
func NewResource(uri string) Resource {
|
|
r, e := ResourceTypes.New(uri)
|
|
if e == nil {
|
|
return r
|
|
}
|
|
return nil
|
|
}
|
|
/*
|
|
func Machine() {
|
|
// start_destroy -> absent -> start_create -> present -> start_destroy
|
|
stater := machine.New("absent")
|
|
stater.AddStates("absent", "start_create", "present", "start_delete")
|
|
stater.AddTransition("creating", "absent", "start_create")
|
|
stater.AddTransition("created", "start_create", "present")
|
|
stater.AddTransition("deleting", "present", "start_delete")
|
|
stater.AddTransition("deleted", "start_delete", "absent")
|
|
}
|
|
*/
|