diff --git a/auto b/auto new file mode 100755 index 0000000..146c5ea --- /dev/null +++ b/auto @@ -0,0 +1,9 @@ +#!/usr/bin/env bash + +while true; do + find . -type f -not -name modularium \ + | grep -v '.git' \ + | entr -c -d -r ./devloop + sleep 0.25 +done + diff --git a/devloop b/devloop new file mode 100755 index 0000000..09d7c6b --- /dev/null +++ b/devloop @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +set -e + +/home/jordan/code/go/bin/go test +/home/jordan/code/go/bin/go build +./modularium serve diff --git a/handler.go b/handler.go index 7e8ad6e..13a6a53 100644 --- a/handler.go +++ b/handler.go @@ -62,19 +62,30 @@ func (h handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { switch r.URL.Path { case "/fart": + // Step 1: a request comes in at orel.li. This page contains a meta tag + // indicating where the package contents may be found, and which backend + // is serving the package. serveFile(w, "meta/fart/root.html") case "/modules/orel.li/fart/@v/list": + // Step 2: list all of the versions for the package. Versions may be + // available but unlisted. serveFile(w, "meta/fart/version-list") case "/modules/orel.li/fart/@latest", "/modules/orel.li/fart/@v/v0.0.3.info": + // Step 3: get info for the version, which is just a timestamp at the + // moment. e := json.NewEncoder(w) e.Encode(versionInfo{ Version: "v0.0.3", Time: time.Now(), }) case "/modules/orel.li/fart/@v/v0.0.3.mod": + // Step 4: retrieve the modfile for the package, informing go mod of + // any transitive dependencies. serveFile(w, "meta/fart/modfile") case "/modules/orel.li/fart/@v/v0.0.3.zip": + // Step 5: retrieve the source code contents for a package, as a + // specially-formatted zip file. err := zip.CreateFromDir(w, module.Version{ Path: "orel.li/fart", Version: "v0.0.3", diff --git a/index.json b/index.json index f1090af..4f81993 100644 --- a/index.json +++ b/index.json @@ -1,11 +1,12 @@ { "orel.li": { "fart": { - "list_versions": [ + "listed": [ "0.0.1", "0.0.2", "0.0.3" - ] + ], + "latest": "0.0.3" } } } diff --git a/internal/index/domain.go b/internal/index/domain.go new file mode 100644 index 0000000..2430a7a --- /dev/null +++ b/internal/index/domain.go @@ -0,0 +1,5 @@ +package index + +type Domain struct { + Packages map[string][]Version `json:"packages"` +} diff --git a/internal/index/index.go b/internal/index/index.go new file mode 100644 index 0000000..fdb9439 --- /dev/null +++ b/internal/index/index.go @@ -0,0 +1,24 @@ +package index + +import ( + "encoding/json" + "fmt" + "os" +) + +// Index maps package path roots to their domains +type Index map[string]Domain + +func Load(path string) (Index, error) { + f, err := os.Open(path) + if err != nil { + return nil, fmt.Errorf("failed to load index at path %q: %w", path, err) + } + defer f.Close() + + var i Index + if err := json.NewDecoder(f).Decode(&i); err != nil { + return nil, fmt.Errorf("failed to parse index file at %q: %w", path, err) + } + return i, nil +} diff --git a/internal/index/json.go b/internal/index/json.go new file mode 100644 index 0000000..60a0228 --- /dev/null +++ b/internal/index/json.go @@ -0,0 +1 @@ +package index diff --git a/internal/index/root.go b/internal/index/root.go new file mode 100644 index 0000000..f4ba1ef --- /dev/null +++ b/internal/index/root.go @@ -0,0 +1,5 @@ +package index + +type Root struct { + Path string +} diff --git a/internal/index/version.go b/internal/index/version.go new file mode 100644 index 0000000..db8576a --- /dev/null +++ b/internal/index/version.go @@ -0,0 +1,4 @@ +package index + +type Version struct { +} diff --git a/main.go b/main.go index d01513f..d0e5290 100644 --- a/main.go +++ b/main.go @@ -9,6 +9,7 @@ import ( "os" "os/signal" + "orel.li/modularium/internal/index" "orel.li/modularium/internal/ref" ) @@ -47,19 +48,25 @@ func main() { switch root.Arg(0) { case "serve": - path := "/var/run/orel.li/http.sock" - index := pathArg{path: "./modules-index.json"} + path := "./modularium.sock" + indexPath := pathArg{path: "./modules-index.json"} h := handler{ path: ref.New(&path), - index: ref.New(&index), + index: ref.New(&indexPath), } serveFlags := flag.NewFlagSet("serve", flag.ExitOnError) serveFlags.StringVar(&path, "l", path, "path for a unix domain socket to listen on") - serveFlags.Var(&index, "index", "an index config") + serveFlags.Var(&indexPath, "index", "an index config") serveFlags.Parse(root.Args()[1:]) + idx, err := index.Load(indexPath.path) + if err != nil { + shutdown(err) + } + log_info.Printf("index: %v", idx) + if err := h.run(); err != nil { bail(1, err.Error()) } diff --git a/modules-index.json b/modules-index.json new file mode 100644 index 0000000..5ba7da1 --- /dev/null +++ b/modules-index.json @@ -0,0 +1,4 @@ +{ + "orel.li": {} +} +