33 lines
704 B
Go
33 lines
704 B
Go
package contracts
|
|
|
|
import (
|
|
"embed"
|
|
"encoding/json"
|
|
"fmt"
|
|
"path"
|
|
)
|
|
|
|
// Files is the immutable contract bundle imported from the parent repository.
|
|
// The bundle is copied from a recorded parent commit; runtime code never reads
|
|
// the parent worktree.
|
|
//
|
|
//go:embed upstream
|
|
var Files embed.FS
|
|
|
|
const SourceCommit = "v1"
|
|
|
|
func Read(name string) ([]byte, error) {
|
|
return Files.ReadFile(path.Join("upstream", SourceCommit, name))
|
|
}
|
|
|
|
func ReadJSON(name string, dst any) error {
|
|
data, err := Read(name)
|
|
if err != nil {
|
|
return fmt.Errorf("read contract %s: %w", name, err)
|
|
}
|
|
if err := json.Unmarshal(data, dst); err != nil {
|
|
return fmt.Errorf("decode contract %s: %w", name, err)
|
|
}
|
|
return nil
|
|
}
|