diff --git a/registry/apitypes.go b/registry/apitype/apitype.go similarity index 97% rename from registry/apitypes.go rename to registry/apitype/apitype.go index 599bfe9a..e33dfe34 100644 --- a/registry/apitypes.go +++ b/registry/apitype/apitype.go @@ -1,4 +1,4 @@ -package registry +package apitype import "encoding/json" diff --git a/registry/client.go b/registry/client.go index 1e3e9c88..82616380 100644 --- a/registry/client.go +++ b/registry/client.go @@ -6,6 +6,7 @@ import ( "net/http" "bllamo.com/client/ollama" + "bllamo.com/registry/apitype" ) type Client struct { @@ -18,9 +19,9 @@ func (c *Client) oclient() *ollama.Client { } // Push pushes a manifest to the server. -func (c *Client) Push(ctx context.Context, ref string, manifest []byte) ([]Requirement, error) { +func (c *Client) Push(ctx context.Context, ref string, manifest []byte) ([]apitype.Requirement, error) { // TODO(bmizerany): backoff - v, err := ollama.Do[PushResponse](ctx, c.oclient(), "POST", "/v1/push", &PushRequest{ + v, err := ollama.Do[apitype.PushResponse](ctx, c.oclient(), "POST", "/v1/push", &apitype.PushRequest{ Ref: ref, Manifest: manifest, }) diff --git a/registry/server.go b/registry/server.go index f1d03cc5..a12e210c 100644 --- a/registry/server.go +++ b/registry/server.go @@ -13,6 +13,7 @@ import ( "bllamo.com/client/ollama" "bllamo.com/oweb" + "bllamo.com/registry/apitype" "github.com/minio/minio-go/v7" "github.com/minio/minio-go/v7/pkg/credentials" ) @@ -44,7 +45,7 @@ func (s *Server) serveHTTP(w http.ResponseWriter, r *http.Request) error { } func (s *Server) handlePush(w http.ResponseWriter, r *http.Request) error { - pr, err := oweb.DecodeUserJSON[PushRequest]("", r.Body) + pr, err := oweb.DecodeUserJSON[apitype.PushRequest]("", r.Body) if err != nil { return err } @@ -54,13 +55,13 @@ func (s *Server) handlePush(w http.ResponseWriter, r *http.Request) error { Secure: false, }) - m, err := oweb.DecodeUserJSON[Manifest]("manifest", bytes.NewReader(pr.Manifest)) + m, err := oweb.DecodeUserJSON[apitype.Manifest]("manifest", bytes.NewReader(pr.Manifest)) if err != nil { return err } // TODO(bmizerany): parallelize - var requirements []Requirement + var requirements []apitype.Requirement for _, l := range m.Layers { if l.Size == 0 { continue @@ -76,7 +77,7 @@ func (s *Server) handlePush(w http.ResponseWriter, r *http.Request) error { if err != nil { return err } - requirements = append(requirements, Requirement{ + requirements = append(requirements, apitype.Requirement{ Digest: l.Digest, Size: l.Size, @@ -89,7 +90,7 @@ func (s *Server) handlePush(w http.ResponseWriter, r *http.Request) error { // TODO(bmizerany): commit to db // ref, _ := strings.CutPrefix(r.URL.Path, "/v1/push/") - return oweb.EncodeJSON(w, &PushResponse{Requirements: requirements}) + return oweb.EncodeJSON(w, &apitype.PushResponse{Requirements: requirements}) } func (s *Server) handlePull(w http.ResponseWriter, r *http.Request) error { diff --git a/registry/server_test.go b/registry/server_test.go index 1457a0d8..79c1875b 100644 --- a/registry/server_test.go +++ b/registry/server_test.go @@ -8,6 +8,7 @@ import ( "testing" "time" + "bllamo.com/registry/apitype" "github.com/kr/pretty" "github.com/minio/minio-go/v7" "github.com/minio/minio-go/v7/pkg/credentials" @@ -35,11 +36,11 @@ func TestPush(t *testing.T) { t.Fatal(err) } - diff.Test(t, t.Errorf, got, []Requirement{ + diff.Test(t, t.Errorf, got, []apitype.Requirement{ {Digest: "sha256-1", Size: 1}, {Digest: "sha256-2", Size: 2}, {Digest: "sha256-3", Size: 3}, - }, diff.ZeroFields[Requirement]("URL")) + }, diff.ZeroFields[apitype.Requirement]("URL")) for _, r := range got { body := strings.NewReader(strings.Repeat("x", int(r.Size)))