diff options
| -rw-r--r-- | Makefile | 9 | ||||
| -rw-r--r-- | http.go | 2 | ||||
| -rw-r--r-- | main.go | 88 | ||||
| -rw-r--r-- | repomap.go | 2 | 
4 files changed, 88 insertions, 13 deletions
@@ -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 \ @@ -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() @@ -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 @@ -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 {  | 
