From b33280b869b2d79255ccac0250dc476f7add23c9 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Thu, 7 Nov 2024 08:25:11 -0600 Subject: [PATCH] use 'http stdout' via 'log' pkg Signed-off-by: Jeff Carr --- http.go | 70 +++++++++++++++++++++++------------------------- main.go | 1 + simpleRelease.go | 18 +++++++------ 3 files changed, 44 insertions(+), 45 deletions(-) diff --git a/http.go b/http.go index cfa26af..818089d 100644 --- a/http.go +++ b/http.go @@ -17,38 +17,34 @@ func cleanURL(url string) string { return url } -// send stuff to the socket and stdout -func msg(w http.ResponseWriter, s string) { - log.Info(s) - fmt.Fprintln(w, s) -} - func okHandler(w http.ResponseWriter, r *http.Request) { var route string route = cleanURL(r.URL.Path) + log.HttpMode(w) + defer log.HttpMode(nil) if route == "/help" { - msg(w, "uptime/ uptime uptime fun!") - msg(w, "list/ list modified repos") - msg(w, "list?readonly=true shows every repo") - msg(w, "gitpull/ run a git pull in each repo") + log.Info("uptime/ uptime uptime fun!") + log.Info("list/ list modified repos") + log.Info("list?readonly=true shows every repo") + log.Info("gitpull/ run a git pull in each repo") - msg(w, "") - msg(w, "Examples:") - msg(w, "") - msg(w, "not done yet:") + log.Info("") + log.Info("Examples:") + log.Info("") + log.Info("not done yet:") - msg(w, "changes/ show latest changes") - msg(w, "repo?repo=go.wit.com/apps/autotypist show this repo") - msg(w, "clone?repo=go.wit.com/apps/virtigo go-clone a new repo") - msg(w, "build?repo=go.wit.com/apps/autotypist build the autotypist") - msg(w, "debian?repo=go.wit.com/apps/autotypist make a debian package of the autotypist") + log.Info("changes/ show latest changes") + log.Info("repo?repo=go.wit.com/apps/autotypist show this repo") + log.Info("clone?repo=go.wit.com/apps/virtigo go-clone a new repo") + log.Info("build?repo=go.wit.com/apps/autotypist build the autotypist") + log.Info("debian?repo=go.wit.com/apps/autotypist make a debian package of the autotypist") return } if route == "/uptime" { s := "uptime uptime uptime fun!" - msg(w, s) + log.Info(s) return } @@ -65,12 +61,12 @@ func okHandler(w http.ResponseWriter, r *http.Request) { if repo == nil { cmd := []string{"go-clone", repoName} header := repo.StandardHeader() - msg(w, header+strings.Join(cmd, " ")) + log.Info(header + strings.Join(cmd, " ")) shell.RunHttpOut(cmd, w, r) } else { cmd := []string{"git", "pull", "-v"} header := repo.StandardHeader() - msg(w, header+strings.Join(cmd, " ")) + log.Info(header + strings.Join(cmd, " ")) shell.RunPathHttpOut(repo.Status.FullPath(), cmd, w, r) } return @@ -82,10 +78,10 @@ func okHandler(w http.ResponseWriter, r *http.Request) { cmd := []string{"git", "pull", "-v"} header := repo.StandardHeader() if repo.CheckDirty() { - msg(w, header+"skip dirty repo") + log.Info(header + "skip dirty repo") continue } - msg(w, header+strings.Join(cmd, " ")) + log.Info(header + strings.Join(cmd, " ")) shell.RunPathHttpOut(repo.Status.FullPath(), cmd, w, r) } return @@ -105,14 +101,14 @@ func okHandler(w http.ResponseWriter, r *http.Request) { header := repo.StandardHeader() if onlydirty == "true" { if repo.CheckDirty() { - msg(w, header+"") + log.Info(header + "") } continue } if repo.ReadOnly() { if readonly == "true" { - msg(w, header+"readonly") + log.Info(header + "readonly") } continue } @@ -122,16 +118,16 @@ func okHandler(w http.ResponseWriter, r *http.Request) { } } if repo.State() != "merge to main" { - msg(w, header+"") + log.Info(header + "") continue } if repo.CheckDirty() { - msg(w, header+"") + log.Info(header + "") continue } - msg(w, header+"") + log.Info(header + "") } - msg(w, fmt.Sprintf("EVERYTHING WORKED repo count = %d", count)) + log.Info(fmt.Sprintf("EVERYTHING WORKED repo count = %d", count)) return } if route == "/goweblist" { @@ -143,7 +139,7 @@ func okHandler(w http.ResponseWriter, r *http.Request) { tag := repo.Status.NewestTag() gitAge, err := tag.GetDate() if err != nil { - msg(w, fmt.Sprintf("tag date error", repo.Name())) + log.Info(fmt.Sprintf("tag date error", repo.Name())) } // if lastTag == "" { // lastTag = tag.Name() @@ -154,11 +150,11 @@ func okHandler(w http.ResponseWriter, r *http.Request) { } } // dur := time.Since(gitAge) - // msg(w, fmt.Sprintf("%-60s %s %s %s", repo.Name(), lastTag, shell.FormatDuration(dur), lastTag, tag.Name())) - msg(w, fmt.Sprintf("%s %d %s", repo.Name(), gitAge.Unix(), lastTag)) + // log.Info(fmt.Sprintf("%-60s %s %s %s", repo.Name(), lastTag, shell.FormatDuration(dur), lastTag, tag.Name())) + log.Info(fmt.Sprintf("%s %d %s", repo.Name(), gitAge.Unix(), lastTag)) /* for _, tag := range repo.Tags.ListAll() { - msg(w, fmt.Sprintf("%-60s %s", "", tag.Name())) + log.Info(fmt.Sprintf("%-60s %s", "", tag.Name())) } */ @@ -171,7 +167,7 @@ func okHandler(w http.ResponseWriter, r *http.Request) { // log.Info("addRepo()", i, path) path = strings.TrimPrefix(path, me.goSrcPwd.String()) path = strings.Trim(path, "/") - msg(w, fmt.Sprintf("paths:", i, path)) + log.Info(fmt.Sprintf("paths:", i, path)) } return } @@ -180,11 +176,11 @@ func okHandler(w http.ResponseWriter, r *http.Request) { reponame := r.URL.Query().Get("repo") if reponame == "" { s := "reponame is blank " + cleanURL(r.URL.Path) - msg(w, s) + log.Info(s) return } s := "reponame is " + reponame - msg(w, s) + log.Info(s) return } diff --git a/main.go b/main.go index 41161e8..9cc33c2 100644 --- a/main.go +++ b/main.go @@ -9,6 +9,7 @@ import ( ) var VERSION string + //go:embed resources/* var resources embed.FS var myargv argv diff --git a/simpleRelease.go b/simpleRelease.go index 881bc26..cfd7486 100644 --- a/simpleRelease.go +++ b/simpleRelease.go @@ -4,6 +4,8 @@ import ( "fmt" "net/http" "strings" + + "go.wit.com/log" ) // attempts a simple release @@ -18,22 +20,22 @@ import ( func simpleRelease(w http.ResponseWriter, r *http.Request) { repoName := r.URL.Query().Get("repo") if repoName == "" { - msg(w, "url did not have repo variable") + log.Info("url did not have repo variable") return } // git pull (or go-clone of it doesn't exist) repo := me.repos.View.FindRepoByName(repoName) if repo == nil { - msg(w, "repo unknown: "+repoName) + log.Info("repo unknown: " + repoName) return } header := repo.StandardHeader() if repo.CheckDirty() { - msg(w, header+"skip dirty repo") + log.Info(header + "skip dirty repo") return } if repo.State() == "PERFECT" { - msg(w, header+"already released") + log.Info(header + "already released") return } @@ -42,15 +44,15 @@ func simpleRelease(w http.ResponseWriter, r *http.Request) { if curName != mName { // s := log.Sprintf("\trepo is not working from main branch", curName, "!=", mName) s := fmt.Sprint("repo is not working from main branch ", curName, " != ", mName) - msg(w, s) + log.Info(s) return } cmd := []string{"git", "pull", "-v"} - msg(w, header+strings.Join(cmd, " ")) + log.Info(header + strings.Join(cmd, " ")) if repo.Status.MergeUserToDevel() { - msg(w, "THINGS SEEM OK MergeUserToDevel() returned true.") + log.Info("THINGS SEEM OK MergeUserToDevel() returned true.") } else { - msg(w, "THINGS FAILED MergeUserToDevel() returned false") + log.Info("THINGS FAILED MergeUserToDevel() returned false") } return }