Skip to content
This repository has been archived by the owner on Feb 17, 2024. It is now read-only.

timecraft: add get command #27

Merged
merged 9 commits into from
May 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,19 @@ format.src.go = \
timecraft.src.go = \
$(format.src.go) \
$(wildcard *.go) \
$(wildcard cmd/*.go) \
$(wildcard internal/*/*.go)
$(wildcard */*.go) \
$(wildcard */*/*.go) \
$(wildcard */*/*/*.go)

timecraft: go.mod $(timecraft.src.go)
$(GO) build -o timecraft

clean:
rm -f timecraft $(format.src.go) $(testdata.go.wasm)

lint:
golangci-lint run ./...

generate: flatbuffers

flatbuffers: go.mod $(format.src.go)
Expand Down
41 changes: 26 additions & 15 deletions format/timecraft.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ func SHA256(b []byte) Hash {
}
}

func ParseHash(s string) (h Hash, err error) {
var ok bool
h.Algorithm, h.Digest, ok = strings.Cut(s, ":")
if !ok {
err = fmt.Errorf("malformed hash: %s", s)
}
return h, err
}

func (h Hash) String() string {
return h.Algorithm + ":" + h.Digest
}
Expand Down Expand Up @@ -60,6 +69,8 @@ const (
TypeTimecraftModule MediaType = "application/vnd.timecraft.module.v1+wasm"
)

func (m MediaType) String() string { return string(m) }

type Resource interface {
ContentType() MediaType
}
Expand All @@ -75,11 +86,11 @@ type ResourceUnmarshaler interface {
}

type Descriptor struct {
MediaType MediaType `json:"mediaType"`
Digest Hash `json:"digest"`
Size int64 `json:"size"`
URLs []string `json:"urls,omitempty"`
Annotations map[string]string `json:"annotations,omitempty"`
MediaType MediaType `json:"mediaType" yaml:"mediaType"`
Digest Hash `json:"digest" yaml:"digest"`
Size int64 `json:"size" yaml:"size"`
URLs []string `json:"urls,omitempty" yaml:"urls,omitempty"`
Annotations map[string]string `json:"annotations,omitempty" yaml:"annotations,omitempty"`
}

func (d *Descriptor) ContentType() MediaType {
Expand Down Expand Up @@ -112,7 +123,7 @@ func (m *Module) UnmarshalResource(b []byte) error {
}

type Runtime struct {
Version string `json:"version"`
Version string `json:"version" yaml:"version"`
}

func (r *Runtime) ContentType() MediaType {
Expand All @@ -128,10 +139,10 @@ func (r *Runtime) UnmarshalResource(b []byte) error {
}

type Config struct {
Runtime *Descriptor `json:"runtime"`
Modules []*Descriptor `json:"modules"`
Args []string `json:"args"`
Env []string `json:"env,omitempty"`
Runtime *Descriptor `json:"runtime" yaml:"runtime"`
Modules []*Descriptor `json:"modules" yaml:"modules"`
Args []string `json:"args" yaml:"args"`
Env []string `json:"env,omitempty" yaml:"env,omitempty"`
}

func (c *Config) ContentType() MediaType {
Expand All @@ -147,9 +158,9 @@ func (c *Config) UnmarshalResource(b []byte) error {
}

type Process struct {
ID UUID `json:"id"`
StartTime time.Time `json:"startTime"`
Config *Descriptor `json:"config"`
ID UUID `json:"id" yaml:"id"`
StartTime time.Time `json:"startTime" yaml:"startTime"`
Config *Descriptor `json:"config" yaml:"config"`
}

func (p *Process) ContentType() MediaType {
Expand Down Expand Up @@ -178,8 +189,8 @@ func jsonDecode(b []byte, value any) error {
}

type Manifest struct {
Process *Descriptor `json:"process"`
StartTime time.Time `json:"startTime"`
Process *Descriptor `json:"process" yaml:"process"`
StartTime time.Time `json:"startTime" yaml:"startTime"`
}

func (m *Manifest) ContentType() MediaType {
Expand Down
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ require (
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1
)

require golang.org/x/sys v0.8.0 // indirect
require (
golang.org/x/sys v0.8.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
5 changes: 3 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ github.com/stealthrocket/wasi-go v0.1.1 h1:9Q9zpKWItoObGjNG5kkllzHx1sksiq/MKfuYd
github.com/stealthrocket/wasi-go v0.1.1/go.mod h1:LBhZHvAroNNQTejkVTMJZ01ssj3jXF+3Lkbru4cTzGQ=
github.com/stealthrocket/wazergo v0.19.0 h1:0ZBya2fBURvV+I2hGl0vcuQ8dgoUvllxQ7aYlZSA5nI=
github.com/stealthrocket/wazergo v0.19.0/go.mod h1:riI0hxw4ndZA5e6z7PesHg2BtTftcZaMxRcoiGGipTs=
github.com/stealthrocket/wzprof v0.1.4 h1:Yb/JHAQIpzCrpr/Nw/rgZxqqTigW2HT8SKNs6SLGFV4=
github.com/stealthrocket/wzprof v0.1.4/go.mod h1:lUNsjcNEjviNBV8+MhOGGNBI/SQa7miJQaoXOTgRRok=
github.com/stealthrocket/wzprof v0.1.5-0.20230526193557-ec6e2ad60848 h1:gNZnxEbv7OgKkGvRU4PtGDZpzls81FV0IYoUW3I46l0=
github.com/stealthrocket/wzprof v0.1.5-0.20230526193557-ec6e2ad60848/go.mod h1:hqLzj5iDSncc6rlPMhC51O642AkaC+dWVPNNalZdlCY=
github.com/tetratelabs/wazero v1.1.1-0.20230522055633-256b7a4bf970 h1:X5OOeHRjoLA8XhVc7biEbh1/hnTzpYpPn7HuyarMslQ=
Expand All @@ -22,3 +20,6 @@ golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 h1:k/i9J1pBpvlfR+9QsetwPyERs
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1/go.mod h1:V1LtkGg67GoY2N1AnLN78QLrzxkLyJw7RJb1gzOOz9w=
golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Loading
Loading