small pixel drawing of a pufferfish gore

*
Jes Olson j3s@c3f.net
Mon, 09 Dec 2024 09:21:58 -0500
commit

d1ce3d8ee4de88f898180874a7523c1d3c8a9cb2

parent

81e09b9488c1f97eeb2cf405384236e3ae6161ea

3 files changed, 54 insertions(+), 6 deletions(-)

jump to
M internal/module/module.gointernal/module/module.go

@@ -19,9 +19,9 @@ Version string `json:"Version"`

} type resolvedModule struct { - module string - version string - goMod []byte + Module string + Version string + GoMod []byte } func proxyRequest(importPath, suffix string) (*http.Request, error) {
M main.gomain.go

@@ -1,12 +1,10 @@

package main import ( - "context" "log" "net/http" "j3s.sh/gore/internal/assets" - "j3s.sh/gore/internal/module" ) var (

@@ -19,7 +17,6 @@ http.HandleFunc("GET /", indexHandler)

http.Handle("GET /assets/", http.StripPrefix("/assets/", http.FileServer(http.FS(assets.Assets)))) http.HandleFunc("POST /submit", submitHandler) - module.Resolve(context.TODO(), "git.j3s.sh/vore", "latest") log.Println("Starting Gore server on :6043...") log.Fatal(http.ListenAndServe(":6043", nil)) }
M status.gostatus.go

@@ -2,6 +2,7 @@ package main

import ( "bytes" + "context" "debug/buildinfo" "encoding/json" "fmt"

@@ -18,7 +19,9 @@ "sync/atomic"

"time" "j3s.sh/gore/internal/assets" + "j3s.sh/gore/internal/module" + "golang.org/x/mod/modfile" "golang.org/x/sys/unix" )

@@ -361,6 +364,54 @@ path, version, found := strings.Cut(formInput, "@")

fmt.Println(path, version) if !found { version = "latest" + } + + // First: we resolve da module using le proxies + resolved, err := module.Resolve(context.TODO(), path, version) + if err != nil { + // TODO: error to user + log.Println(err) + return + } + + log.Printf(`Adding the following package to gore: + Go package : %s + in Go module: %s`, path, resolved.Module) + + // Next: we build da binary, based on le module data + buildDir := filepath.Join("builddir", resolved.Module) + if _, err := os.Stat(buildDir); err != nil { + log.Printf("Creating builddir for module %s", resolved.Module) + if err := os.MkdirAll(buildDir, 0755); err != nil { + log.Printf("Failed to create builddir for module %s: %v", resolved.Module, err) + return + } + } + + if _, err := os.Stat(filepath.Join(buildDir, "go.mod")); err == nil { + log.Printf("Adding require line to existing go.mod") + } else { + log.Printf("Creating go.mod based on upstream go.mod") + modf, err := modfile.Parse("go.mod", resolved.GoMod, nil) + if err != nil { + log.Printf("parsing old go.mod: %v", err) + return + } + if err := modf.AddModuleStmt("gokrazy/build/" + resolved.Module); err != nil { + log.Println(err) + return + } + + b, err := modf.Format() + if err != nil { + log.Println(err) + return + } + + if err := os.WriteFile(filepath.Join(buildDir, "go.mod"), b, 0600); err != nil { + log.Println(err) + return + } } // attempt fetch