From d94bfac9bfe8f4a22a1d1cc2840746e3c873fd89 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Tue, 7 Oct 2025 02:50:47 -0500 Subject: start making this dynamic --- Makefile | 9 +------ http.go | 2 +- main.go | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- repomap.go | 2 +- 4 files changed, 88 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index 4f6b3de..59922b6 100644 --- a/Makefile +++ b/Makefile @@ -4,14 +4,7 @@ VERSION = $(shell git describe --tags) BUILDTIME = $(shell date +%Y.%m.%d) all: build - @echo "make build # build" - @echo "make clean # clean build files" - @echo "make run # build and run on port 2233" - @echo "make debian # will build a debian package" - @echo "" - @echo "make restart # restart the daemon" - @echo "make enable # enable daemon on boot" - @echo "make log # watch the daemon log" + ./gowebd test build: goimports GO111MODULE=off go build \ diff --git a/http.go b/http.go index fbd9fc5..3e1afc0 100644 --- a/http.go +++ b/http.go @@ -83,7 +83,7 @@ func okHandler(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "go.wit.com/apps/utils/gowebd Version: %s\n", argv.Version()) fmt.Fprintf(w, "\n") - all := forge.Repos.SortByFullPath() + all := me.forge.Repos.SortByFullPath() for all.Scan() { repo := all.Next() diff --git a/main.go b/main.go index 6e87070..1a2db21 100644 --- a/main.go +++ b/main.go @@ -4,6 +4,7 @@ import ( "embed" "fmt" "net/http" + "strings" "time" "go.wit.com/lib/gui/prep" @@ -26,7 +27,6 @@ var repoMap map[string]string var gitMap map[string]*gitpb.Repo var configfile []string var keysSorted []string -var forge *forgepb.Forge var HOSTNAME string = "go.wit.com" var REPOMAP string = "/etc/gowebd/repomap" @@ -47,11 +47,18 @@ func main() { gitMap = make(map[string]*gitpb.Repo) repoMap = make(map[string]string) - forge = forgepb.Init() + me.forge = forgepb.Init() // parse the repomap file readRepomap() - // readVersionFile() + + if argv.Test != nil { + if s, err := newMakeRepomap(); err != nil { + me.sh.BadExit(s, err) + } else { + me.sh.GoodExit(s) + } + } http.HandleFunc("/", okHandler) // go https() // use caddy instead @@ -64,6 +71,81 @@ func main() { } } +func newMakeRepomap() (string, error) { + submit := gitpb.NewRepos() + for key, val := range repoMap { + if !strings.HasPrefix(key, "go.wit.com") { + // only handling go.wit.com here + continue + } + log.Info(key) + r := new(gitpb.Repo) + r.Namespace = key + r.State = val + submit.Append(r) + } + server := me.forge.GetForgeURL() + updatepb, regPB, err := submit.HttpPost(server, "check") + if err != nil { + log.Info("ReposPB HttpPost() failed", err) + return "HttpPost() failed", err + } + if regPB == nil { + log.Info("regPB==nil") + return "HttpPost() internally returned nil http PB", err + } + if updatepb == nil { + log.Info("server sent nil back nil PB") + return "HttpPost() internally returned nil http PB", err + } + for repo := range updatepb.IterByNamespace() { + log.Info(repo.Namespace, repo.URL) + } + + makePullTable(updatepb) + return "new dynamic repomap!", nil +} + +func makePullTable(pb *gitpb.Repos) { + t := pb.NewTable("pullTable") + t.NewUuid() + + var col *gitpb.RepoFunc + // var col int + + col = t.AddNamespace() + col.Width = 30 + + col = t.AddMasterVersion() + // col.SetTitle("mver") + col.Width = 15 + + col = t.AddStringFunc("Tags", func(r *gitpb.Repo) string { + if r.Tags == nil { + return "nil" + } + log.Infof("repo: %v\n", r) + return log.Sprintf("len(%d)", r.Tags.Len()) + }) + col.Width = 9 + + col = t.AddStringFunc("cur tag", func(r *gitpb.Repo) string { + if r.CurrentTag == nil { + return "nil" + } + return "ok" + }) + col.Width = 9 + + col = t.AddDevelVersion() + col.Width = 15 + + col = t.AddFullPath() + col.Width = -1 + + t.PrintTable() +} + func formatDuration(d time.Duration) string { seconds := int(d.Seconds()) % 60 minutes := int(d.Minutes()) % 60 diff --git a/repomap.go b/repomap.go index 0fa5d18..140d41b 100644 --- a/repomap.go +++ b/repomap.go @@ -65,7 +65,7 @@ func readRepomap() { giturl := fields[1] repoMap[gopath] = giturl - repo := forge.FindByGoPath(gopath) + repo := me.forge.FindByGoPath(gopath) if repo != nil { gitMap[gopath] = repo } else { -- cgit v1.2.3