start putting index in a file

master
Jordan Orelli 3 years ago
parent a2bdee608c
commit 2a8097a6f0

@ -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

@ -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

@ -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",

@ -1,11 +1,12 @@
{
"orel.li": {
"fart": {
"list_versions": [
"listed": [
"0.0.1",
"0.0.2",
"0.0.3"
]
],
"latest": "0.0.3"
}
}
}

@ -0,0 +1,5 @@
package index
type Domain struct {
Packages map[string][]Version `json:"packages"`
}

@ -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
}

@ -0,0 +1 @@
package index

@ -0,0 +1,5 @@
package index
type Root struct {
Path string
}

@ -0,0 +1,4 @@
package index
type Version struct {
}

@ -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())
}

@ -0,0 +1,4 @@
{
"orel.li": {}
}
Loading…
Cancel
Save