Compare commits
13 Commits
Author | SHA1 | Date |
---|---|---|
|
460338c4eb | |
|
cd545c7c9f | |
|
b09b86009e | |
|
1f22b771c3 | |
|
ada923ea05 | |
|
2b6107fa51 | |
|
7a76b5acd1 | |
|
6df342bc10 | |
|
209ee29773 | |
|
43d653a8c0 | |
|
6722b019ec | |
|
82b232f47a | |
|
979fd2f978 |
8
Makefile
8
Makefile
|
@ -1,10 +1,12 @@
|
|||
.PHONY: build
|
||||
|
||||
VERSION = $(shell git describe --tags)
|
||||
BUILDTIME = $(shell date +%Y.%m.%d_%H%M)
|
||||
# BUILDTIME = $(shell date +%Y.%m.%d_%H%M)
|
||||
BUILDTIME = $(shell date +%s)
|
||||
|
||||
all: build-verbose
|
||||
./forged list
|
||||
all: build
|
||||
FORGE_VERBOSE=true ./forged clean
|
||||
# FORGE_VERBOSE=true ./forged list
|
||||
|
||||
build: goimports
|
||||
GO111MODULE=off go build \
|
||||
|
|
64
argv.go
64
argv.go
|
@ -8,6 +8,12 @@ package main
|
|||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"go.wit.com/lib/gui/prep"
|
||||
"go.wit.com/lib/gui/shell"
|
||||
)
|
||||
|
||||
var argv args
|
||||
|
@ -15,30 +21,66 @@ var argv args
|
|||
type args struct {
|
||||
Pull *EmptyCmd `arg:"subcommand:pull" help:"'git pull' on the repos"`
|
||||
List *EmptyCmd `arg:"subcommand:list" help:"list the repos"`
|
||||
Clean *EmptyCmd `arg:"subcommand:clean" help:"clean the repos"`
|
||||
Gui *EmptyCmd `arg:"subcommand:gui" help:"show gui"`
|
||||
Merge *EmptyCmd `arg:"subcommand:merge" help:"merge in new patchsets"`
|
||||
Init *EmptyCmd `arg:"subcommand:init" help:"init the repo list"`
|
||||
Port int `arg:"--port" default:"2520" help:"port to run on"`
|
||||
Hostname string `arg:"--hostname" default:"forge.wit.com" help:"hostname to use"`
|
||||
Daemon bool `arg:"--daemon" help:"run as a daemon"`
|
||||
Force bool `arg:"--force" help:"try to strong arm things"`
|
||||
Verbose bool `arg:"--verbose" help:"show more output"`
|
||||
Repos *EmptyCmd `arg:"subcommand:repos" help:"show the repos"`
|
||||
Port int `arg:"--port" default:"2520" help:"port to run on"`
|
||||
Hostname string `arg:"--hostname" help:"hostname to use"`
|
||||
Daemon bool `arg:"--daemon" help:"run as a daemon"`
|
||||
Force bool `arg:"--force" help:"try to strong arm things"`
|
||||
Verbose bool `arg:"--verbose" help:"show more output"`
|
||||
}
|
||||
|
||||
type EmptyCmd struct {
|
||||
}
|
||||
|
||||
func (args) Appname() string {
|
||||
return ARGNAME
|
||||
}
|
||||
|
||||
func (args) Version() string {
|
||||
parts := strings.Split(BUILDTIME, ".")
|
||||
if len(parts) == 1 {
|
||||
// The input epoch seconds
|
||||
// epochSeconds := int64(1758646486)
|
||||
num, err := strconv.Atoi(BUILDTIME)
|
||||
epochSeconds := int64(num)
|
||||
if err == nil {
|
||||
|
||||
// 1. Convert the epoch seconds to a time.Time object.
|
||||
// time.Unix() creates the time in the UTC timezone by default.
|
||||
t := time.Unix(epochSeconds, 0)
|
||||
|
||||
// 2. Convert the UTC time to the computer's local timezone.
|
||||
localTime := t.Local()
|
||||
|
||||
// 3. Print the result. The default format is clear and includes the timezone.
|
||||
// fmt.Println("Default format:", localTime)
|
||||
// For a more human-friendly format, use the Format() method.
|
||||
// Go uses a special reference time for formatting: Mon Jan 2 15:04:05 2006 MST
|
||||
// You lay out your desired format using these specific numbers.
|
||||
// formattedString := localTime.Format("Monday, January 2, 2006 at 3:04:05 PM (MST)")
|
||||
// fmt.Println(" Custom format:", formattedString)
|
||||
|
||||
// now := time.Now()
|
||||
// dur := time.Since(localTime)
|
||||
BUILDTIME = fmt.Sprintf("%s age(%v)", localTime.String(), shell.FormatDuration(time.Since(localTime)))
|
||||
}
|
||||
}
|
||||
|
||||
return ARGNAME + " " + VERSION + " Built on " + BUILDTIME
|
||||
}
|
||||
|
||||
func (a args) DoAutoComplete(argv []string) {
|
||||
// argv.doBashHelp()
|
||||
switch argv[0] {
|
||||
case "merge":
|
||||
fmt.Println("--force")
|
||||
func (a args) DoAutoComplete(pb *prep.Auto) {
|
||||
switch pb.Cmd {
|
||||
case "list":
|
||||
pb.Autocomplete2("--missing")
|
||||
case "clean":
|
||||
pb.Autocomplete2("")
|
||||
default:
|
||||
fmt.Println("list merge")
|
||||
pb.Autocomplete2("list clean")
|
||||
}
|
||||
os.Exit(0)
|
||||
}
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
package main
|
||||
|
||||
// functions to import and export the protobuf
|
||||
// data to and from config files
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"go.wit.com/lib/config"
|
||||
"go.wit.com/lib/protobuf/forgepb"
|
||||
"go.wit.com/log"
|
||||
)
|
||||
|
||||
func configSave() error {
|
||||
return me.configs.ConfigSave()
|
||||
}
|
||||
|
||||
func configInit() *forgepb.ForgeConfigs {
|
||||
if argv.Hostname != "" {
|
||||
HOSTNAME = argv.Hostname
|
||||
}
|
||||
|
||||
// the default forged dir is /home/forge
|
||||
if os.Getenv("FORGE_REPODIR") == "" {
|
||||
os.Setenv("FORGE_REPODIR", "/home/forge")
|
||||
}
|
||||
|
||||
if os.Getenv("FORGE_PATCHDIR") == "" {
|
||||
os.Setenv("FORGE_PATCHDIR", "/var/lib/forged")
|
||||
}
|
||||
|
||||
configs := new(forgepb.ForgeConfigs)
|
||||
err := config.ConfigLoad(configs, ARGNAME, "forge")
|
||||
if errors.Is(err, os.ErrNotExist) {
|
||||
configs.ReposDir = os.Getenv("FORGE_REPODIR")
|
||||
configs.ReposPB = filepath.Join(configs.ReposDir, "repos.pb")
|
||||
configs.PatchDir = os.Getenv("FORGE_PATCHDIR")
|
||||
if err := configSave(); err != nil {
|
||||
badExit(err)
|
||||
}
|
||||
log.Info("made a default config file here", configs.Filename)
|
||||
okExit("")
|
||||
}
|
||||
if err != nil {
|
||||
badExit(err)
|
||||
}
|
||||
return configs
|
||||
}
|
20
doList.go
20
doList.go
|
@ -6,15 +6,27 @@ import (
|
|||
)
|
||||
|
||||
func doList() error {
|
||||
log.Info("do list here")
|
||||
log.Infof("do list here. Patchsets.Len()=%d\n", me.forge.Patchsets.Len())
|
||||
for pset := range me.forge.Patchsets.IterAll() {
|
||||
pset.PrintTable()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func doClean() error {
|
||||
log.Infof("clean Patchsets.Len()=%d\n", me.forge.Patchsets.Len())
|
||||
// show all the patchsets with Names
|
||||
for pset := range me.forge.Patchsets.IterAll() {
|
||||
log.Info("Info", pset.Name, pset.Uuid)
|
||||
for i, patch := range pset.Patches.Patches {
|
||||
log.Info("\t", i, patch.CommitHash, patch.Namespace)
|
||||
for patch := range pset.Patches.IterAll() {
|
||||
if patch.PatchId == "" {
|
||||
log.Info("Delete", patch.CommitHash, patch.PatchId, patch.Namespace)
|
||||
pset.Patches.Delete(patch)
|
||||
} else {
|
||||
log.Info("\t", patch.CommitHash, patch.PatchId, patch.Namespace)
|
||||
}
|
||||
}
|
||||
}
|
||||
me.forge.SavePatchsets()
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
18
doMerge.go
18
doMerge.go
|
@ -21,7 +21,7 @@ func doMerge() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func findAutoPatchset() *forgepb.Patchset {
|
||||
func findAutoPatchset() *forgepb.Set {
|
||||
for pset := range me.forge.Patchsets.IterAll() {
|
||||
if pset.Name == "forge auto commit" {
|
||||
return pset
|
||||
|
@ -29,14 +29,14 @@ func findAutoPatchset() *forgepb.Patchset {
|
|||
}
|
||||
}
|
||||
|
||||
var fauto *forgepb.Patchset
|
||||
var fauto *forgepb.Set
|
||||
log.Warn("findAutoPatchset() had to create 'forge auto commit'")
|
||||
if fauto == nil {
|
||||
fauto = new(forgepb.Patchset)
|
||||
fauto = new(forgepb.Set)
|
||||
fauto.Name = "forge auto commit"
|
||||
fauto.Patches = forgepb.NewPatches()
|
||||
fauto.Uuid = uuid.New().String()
|
||||
me.forge.Patchsets.Patchsets = append(me.forge.Patchsets.Patchsets, fauto)
|
||||
me.forge.Patchsets.Append(fauto)
|
||||
}
|
||||
return fauto
|
||||
}
|
||||
|
@ -63,7 +63,7 @@ func addRandomPatch(patch *forgepb.Patch) error {
|
|||
|
||||
/*
|
||||
// adds a patchset or just the patches
|
||||
func addPatchset(filename string, pb *forgepb.Patchset) {
|
||||
func addPatchset(filename string, pb *forgepb.Set) {
|
||||
// if the name of the patchset is "forge auto commit"
|
||||
// then just add all the patches
|
||||
if pb.Name == "forge auto commit" {
|
||||
|
@ -96,8 +96,8 @@ func addPatchset(filename string, pb *forgepb.Patchset) {
|
|||
}
|
||||
|
||||
// Clone() this protobuf into me.forge.Patchsets
|
||||
var newpb *forgepb.Patchset
|
||||
newpb = proto.Clone(pb).(*forgepb.Patchset)
|
||||
var newpb *forgepb.Set
|
||||
newpb = proto.Clone(pb).(*forgepb.Set)
|
||||
if newpb != nil {
|
||||
me.forge.Patchsets.Patchsets = append(me.forge.Patchsets.Patchsets, newpb)
|
||||
}
|
||||
|
@ -122,8 +122,8 @@ func mergePatchsets() {
|
|||
fmt.Println(entry.Name(), err)
|
||||
continue
|
||||
}
|
||||
var p *forgepb.Patchset
|
||||
p = new(forgepb.Patchset)
|
||||
var p *forgepb.Set
|
||||
p = new(forgepb.Set)
|
||||
err = p.Unmarshal(bytes)
|
||||
if err != nil {
|
||||
fmt.Println(entry.Name(), err)
|
||||
|
|
|
@ -14,7 +14,7 @@ func addNewPatches(pb *forgepb.Patches, reqPB *httppb.HttpRequest) *forgepb.Patc
|
|||
me.forge.AddNewPatch(newpatch)
|
||||
newPatchesPB.Append(newpatch)
|
||||
}
|
||||
reqPB.Log = append(reqPB.Log, log.Sprintf("Recived %d patches from client", newPatchesPB.Len()))
|
||||
reqPB.Logf("Recived %d patches from client", newPatchesPB.Len())
|
||||
return newPatchesPB
|
||||
}
|
||||
|
||||
|
@ -38,8 +38,8 @@ func sendPendingPatches(pb *forgepb.Patches, reqPB *httppb.HttpRequest) *forgepb
|
|||
return allPatchesPB
|
||||
}
|
||||
|
||||
func sendPendingPatchsets(pb *forgepb.Patchsets, reqPB *httppb.HttpRequest) *forgepb.Patchsets {
|
||||
allPatchsetsPB := new(forgepb.Patchsets)
|
||||
func sendPendingPatchsets(pb *forgepb.Sets, reqPB *httppb.HttpRequest) *forgepb.Sets {
|
||||
allPatchsetsPB := new(forgepb.Sets)
|
||||
for pset := range me.forge.Patchsets.IterAll() {
|
||||
allPatchsetsPB.Append(pset)
|
||||
}
|
||||
|
@ -54,8 +54,8 @@ func makePatchesPB(reqPB *httppb.HttpRequest) (*forgepb.Patches, error) {
|
|||
}
|
||||
*/
|
||||
|
||||
func makePatchsetsPB(reqPB *httppb.HttpRequest) (*forgepb.Patchsets, error) {
|
||||
pb := forgepb.NewPatchsets()
|
||||
func makePatchsetsPB(reqPB *httppb.HttpRequest) (*forgepb.Sets, error) {
|
||||
pb := forgepb.NewSets()
|
||||
err := pb.Unmarshal(reqPB.ServerData)
|
||||
return pb, err
|
||||
}
|
||||
|
|
221
http.go
221
http.go
|
@ -2,7 +2,6 @@ package main
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
|
@ -12,45 +11,9 @@ import (
|
|||
"go.wit.com/log"
|
||||
)
|
||||
|
||||
// remove '?' part and trailing '/'
|
||||
func cleanURL(url string) string {
|
||||
url = "/" + strings.Trim(url, "/")
|
||||
return url
|
||||
}
|
||||
|
||||
func getIpSimple(r *http.Request) string {
|
||||
host, _, err := net.SplitHostPort(r.RemoteAddr)
|
||||
if err != nil {
|
||||
log.Printf("could not split host port: %v", err)
|
||||
return r.RemoteAddr // Fallback
|
||||
}
|
||||
return host
|
||||
}
|
||||
|
||||
// getClientIP inspects the request for common headers to find the true client IP.
|
||||
func getClientIP(r *http.Request) string {
|
||||
// Caddy sets the X-Forwarded-For header.
|
||||
if forwardedFor := r.Header.Get("X-Forwarded-For"); forwardedFor != "" {
|
||||
// The header can be a comma-separated list of IPs. The first one is the original client.
|
||||
ips := strings.Split(forwardedFor, ",")
|
||||
return strings.TrimSpace(ips[0])
|
||||
}
|
||||
|
||||
// Fallback to RemoteAddr if the header is not present.
|
||||
host, _, err := net.SplitHostPort(r.RemoteAddr)
|
||||
if err != nil {
|
||||
return r.RemoteAddr
|
||||
}
|
||||
return host
|
||||
}
|
||||
|
||||
func whoSent(r *http.Request) string {
|
||||
return log.Sprintf("%s\t%s", getClientIP(r), r.Header.Get("hostname"))
|
||||
}
|
||||
|
||||
func logReqPB(pb *httppb.HttpRequest) {
|
||||
log.Info("LOG: httppb.HttpRequest START:")
|
||||
for i, line := range pb.Log {
|
||||
for i, line := range pb.Logs {
|
||||
log.Infof("%d, URL:%s LINE: %s\n", int(i), pb.URL, line)
|
||||
}
|
||||
log.Info("LOG: httppb.HttpRequest END")
|
||||
|
@ -58,16 +21,12 @@ func logReqPB(pb *httppb.HttpRequest) {
|
|||
|
||||
func okHandler(w http.ResponseWriter, r *http.Request) {
|
||||
reqPB, err := httppb.ReqToPB(r)
|
||||
reqPB.Log = append(reqPB.Log, fmt.Sprintf("START: Got %d bytes from the client", len(reqPB.ClientData)))
|
||||
reqPB.Logf("START: Got %d bytes from the client", len(reqPB.ClientData))
|
||||
if err != nil {
|
||||
reqPB.Log = append(reqPB.Log, fmt.Sprintf("httppb err %v", err))
|
||||
reqPB.Logf("httppb err %v", err)
|
||||
}
|
||||
|
||||
who := whoSent(r)
|
||||
|
||||
route := reqPB.Route
|
||||
parts := strings.Split(route, "?")
|
||||
requrl := parts[0]
|
||||
|
||||
if route == "/" {
|
||||
w.Header().Set("Content-Type", "text")
|
||||
|
@ -76,30 +35,75 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
reqPB.Log = append(reqPB.Log, log.Sprintf("forged REQUEST URL=%s", requrl))
|
||||
|
||||
if strings.HasPrefix(route, "/repos/") {
|
||||
pb := gitpb.NewRepos()
|
||||
if err := pb.Unmarshal(reqPB.ClientData); err == nil {
|
||||
reqPB.Log = append(reqPB.Log, log.Sprintf("Repos Unmarshal() len=%d", pb.Len()))
|
||||
reqPB.Logf("Repos Unmarshal() len=%d", pb.Len())
|
||||
} else {
|
||||
reqPB.Log = append(reqPB.Log, log.Sprintf("Repos Unmarshal() err=%v", err))
|
||||
reqPB.Logf("Repos Unmarshal() err=%v", err)
|
||||
}
|
||||
result := gitpb.NewRepos()
|
||||
switch route {
|
||||
case "/repos/check":
|
||||
result = addRequest(pb, reqPB)
|
||||
reqPB.Log = append(reqPB.Log, log.Sprintf("repos check result.Len()=%d pb.Len()=%d\n", result.Len(), pb.Len()))
|
||||
reqPB.Logf("repos check result.Len()=%d pb.Len()=%d", result.Len(), pb.Len())
|
||||
case "/repos/pull":
|
||||
result = pullRequest(pb, reqPB)
|
||||
case "/repos/add":
|
||||
result = addRequest(pb, reqPB)
|
||||
default:
|
||||
reqPB.Log = append(reqPB.Log, log.Sprintf("repos check result.Len()=%d pb.Len()=%d\n", result.Len(), pb.Len()))
|
||||
reqPB.Logf("repos check result.Len()=%d pb.Len()=%d", result.Len(), pb.Len())
|
||||
log.Info("repos", route, "unknown")
|
||||
}
|
||||
if err := result.SendReply(w, reqPB); err != nil {
|
||||
reqPB.Log = append(reqPB.Log, log.Sprintf("Oh well, Send to client failed. err=%v", err))
|
||||
reqPB.Logf("Oh well, Send to client failed. err=%v", err)
|
||||
}
|
||||
// todo: logReq(reqPB)
|
||||
logReqPB(reqPB)
|
||||
return
|
||||
}
|
||||
|
||||
if strings.HasPrefix(route, "/set/") {
|
||||
pb := new(forgepb.Set)
|
||||
if err := pb.Unmarshal(reqPB.ClientData); err != nil {
|
||||
reqPB.Logf("Patches Unmarshal() len(data)=%d err=%v", len(reqPB.ClientData), err)
|
||||
logReqPB(reqPB)
|
||||
return
|
||||
}
|
||||
reqPB.Logf("Patches Unmarshal() len=%d", pb.Patches.Len())
|
||||
result := new(forgepb.Set)
|
||||
switch route {
|
||||
case "/set/new":
|
||||
me.forge.Patchsets.Append(pb)
|
||||
reqPB.Logf("addNewPatches() pb.Patches.Len()=%d Patchsets.Len()=%d", pb.Patches.Len(), me.forge.Patchsets.Len())
|
||||
me.forge.SavePatchsets()
|
||||
result.Uuid = pb.Uuid
|
||||
default:
|
||||
}
|
||||
if err := result.SendReply(w, reqPB); err != nil {
|
||||
reqPB.Logf("Oh well, Send to client failed. err=%v", err)
|
||||
}
|
||||
// todo: logReq(reqPB)
|
||||
logReqPB(reqPB)
|
||||
return
|
||||
}
|
||||
|
||||
if strings.HasPrefix(route, "/sets/") {
|
||||
pb := forgepb.NewSets()
|
||||
if err := pb.Unmarshal(reqPB.ClientData); err != nil {
|
||||
reqPB.Logf("Patches Unmarshal() len(data)=%d err=%v", len(reqPB.ClientData), err)
|
||||
logReqPB(reqPB)
|
||||
return
|
||||
}
|
||||
reqPB.Logf("Patches Unmarshal() len=%d", pb.Len())
|
||||
switch route {
|
||||
case "/sets/get":
|
||||
if err := me.forge.Patchsets.SendReply(w, reqPB); err != nil {
|
||||
reqPB.Logf("Oh well, Send to client failed. err=%v", err)
|
||||
} else {
|
||||
reqPB.Logf("SendReply() worked")
|
||||
}
|
||||
default:
|
||||
}
|
||||
// todo: logReq(reqPB)
|
||||
logReqPB(reqPB)
|
||||
|
@ -109,19 +113,19 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
|
|||
if strings.HasPrefix(route, "/patches/") {
|
||||
pb := forgepb.NewPatches()
|
||||
if err := pb.Unmarshal(reqPB.ClientData); err == nil {
|
||||
reqPB.Log = append(reqPB.Log, log.Sprintf("Patches Unmarshal() len=%d", pb.Len()))
|
||||
reqPB.Logf("Patches Unmarshal() len=%d", pb.Len())
|
||||
} else {
|
||||
reqPB.Log = append(reqPB.Log, log.Sprintf("Patches Unmarshal() err=%v", err))
|
||||
reqPB.Logf("Patches Unmarshal() err=%v", err)
|
||||
}
|
||||
result := forgepb.NewPatches()
|
||||
switch route {
|
||||
case "/patches/new":
|
||||
result = addNewPatches(pb, reqPB)
|
||||
reqPB.Log = append(reqPB.Log, log.Sprintf("addNewPatches() pb.Len()=%d result.Len()=%d\n", pb.Len(), result.Len()))
|
||||
reqPB.Logf("addNewPatches() pb.Len()=%d result.Len()=%d", pb.Len(), result.Len())
|
||||
case "/patches/applied":
|
||||
reqPB.Log = append(reqPB.Log, log.Sprintf("not really anything needs to be done on applied patches?"))
|
||||
reqPB.Log("not really anything needs to be done on applied patches?")
|
||||
case "/patches/merged":
|
||||
reqPB.Log = append(reqPB.Log, log.Sprintf("a maintainer has merged these patches"))
|
||||
reqPB.Log("a maintainer has merged these patches")
|
||||
result = handleMergedPatches(pb, reqPB)
|
||||
// result = handleAppliedPatches(pb, reqPB)
|
||||
case "/patches/get":
|
||||
|
@ -130,7 +134,7 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
|
|||
result = addNewPatches(pb, reqPB)
|
||||
}
|
||||
if err := result.SendReply(w, reqPB); err != nil {
|
||||
reqPB.Log = append(reqPB.Log, log.Sprintf("Oh well, Send to client failed. err=%v", err))
|
||||
reqPB.Logf("Oh well, Send to client failed. err=%v", err)
|
||||
}
|
||||
me.forge.SavePatchsets()
|
||||
// todo: logReq(reqPB)
|
||||
|
@ -141,9 +145,9 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
|
|||
if strings.HasPrefix(route, "/patchsets/") {
|
||||
pb, err := makePatchsetsPB(reqPB)
|
||||
if err != nil {
|
||||
reqPB.Log = append(reqPB.Log, log.Sprintf("%v", err))
|
||||
reqPB.Logf("%v", err)
|
||||
}
|
||||
result := forgepb.NewPatchsets()
|
||||
result := forgepb.NewSets()
|
||||
switch route {
|
||||
case "/patches/get":
|
||||
result = sendPendingPatchsets(pb, reqPB)
|
||||
|
@ -163,111 +167,28 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
// used for uptime monitor checking
|
||||
if route == "/uptime" {
|
||||
writeFile(w, "uptime.html")
|
||||
httppb.WriteFile(w, resources, "uptime.html")
|
||||
return
|
||||
}
|
||||
|
||||
/*
|
||||
if route == "/lookup" {
|
||||
log.Info("doing lookup len(reqPB.Body) =", len(reqPB.Body))
|
||||
found, err := lookupRepos(reqPB.Body)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
found.SendPB(w)
|
||||
return
|
||||
}
|
||||
*/
|
||||
/*
|
||||
if strings.HasPrefix(route, "/patches/") {
|
||||
pb, err := forgepb.GetPatchesFromHttp(reqPB)
|
||||
if err != nil {
|
||||
log.Info("error converting to patches PB")
|
||||
return
|
||||
}
|
||||
handlePatches(w, pb)
|
||||
return
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
if route == "/patchset" {
|
||||
if err := savePatchset(w, reqPB.Body); err != nil {
|
||||
log.Warn("forged /patchset error", err)
|
||||
return
|
||||
}
|
||||
if err := me.forge.SavePatchsets(); err != nil {
|
||||
log.Warn("savePatchsets() failed", err)
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if route == "/lookup" {
|
||||
log.Info("doing lookup len(reqPB.Body) =", len(reqPB.Body))
|
||||
found, err := lookupRepos(reqPB.Body)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
found.SendPB(w)
|
||||
return
|
||||
}
|
||||
|
||||
if route == "/update" {
|
||||
log.Info("doing update len(reqPB.Body) =", len(reqPB.Body))
|
||||
found, err := updateRepos(reqPB.Body)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
found.SendPB(w)
|
||||
return
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
if route == "/GetPatchsets" || route == "/patchsets/get" {
|
||||
data, err := me.forge.Patchsets.Marshal()
|
||||
if err != nil {
|
||||
log.Info("patchsets.Marshal() to wire failed", err)
|
||||
return
|
||||
}
|
||||
|
||||
start := time.Now()
|
||||
log.Info("going to w.Write(data) with len", len(data))
|
||||
w.Write(data)
|
||||
|
||||
age := shell.FormatDuration(time.Since(start))
|
||||
log.Printf("Done with xfer in (%s). happy hacking!\n", age)
|
||||
return
|
||||
}
|
||||
|
||||
if route == "/patchsetget" {
|
||||
filename := r.URL.Query().Get("filename")
|
||||
getPatchset(w, filename)
|
||||
return
|
||||
}
|
||||
*/
|
||||
|
||||
if route == "/goReference.svg" {
|
||||
w.Header().Set("Content-Type", "image/svg+xml")
|
||||
writeFile(w, "goReference.svg")
|
||||
httppb.WriteFile(w, resources, "goReference.svg")
|
||||
return
|
||||
}
|
||||
if route == "/skeleton.v2.css" {
|
||||
writeFile(w, "skeleton.v2.css")
|
||||
httppb.WriteFile(w, resources, "skeleton.v2.css")
|
||||
return
|
||||
}
|
||||
if route == "/favicon.ico" {
|
||||
writeFile(w, "ipv6.png")
|
||||
httppb.WriteFile(w, resources, "ipv6.png")
|
||||
return
|
||||
}
|
||||
log.Warn("BAD URL =", requrl, "from", who)
|
||||
log.Warn("BAD URL =", reqPB.URL, "from", reqPB.IP, "author", reqPB.Hostname)
|
||||
badurl(w, r.URL.String())
|
||||
}
|
||||
|
||||
/*
|
||||
func writeFile(w http.ResponseWriter, filename string) {
|
||||
// fmt.Fprintln(w, "GOT TEST?")
|
||||
fullname := "resources/" + filename
|
||||
|
@ -281,8 +202,8 @@ func writeFile(w http.ResponseWriter, filename string) {
|
|||
var repohtml string
|
||||
repohtml = string(pfile)
|
||||
fmt.Fprintln(w, repohtml)
|
||||
// log.Println("writeFile() found internal file:", filename)
|
||||
}
|
||||
*/
|
||||
|
||||
func badurl(w http.ResponseWriter, badurl string) {
|
||||
fmt.Fprintln(w, "<!DOCTYPE html>")
|
||||
|
@ -291,7 +212,7 @@ func badurl(w http.ResponseWriter, badurl string) {
|
|||
fmt.Fprintln(w, " <meta http-equiv=\"refresh\" content=\"3; url=https://"+HOSTNAME+"/\">")
|
||||
fmt.Fprintln(w, " </head>")
|
||||
fmt.Fprintln(w, " <body>")
|
||||
fmt.Fprintln(w, " IPv4 IS NOT SUPPORTED<br>")
|
||||
fmt.Fprintln(w, " IPv4 MAY NOT WORK<br>")
|
||||
fmt.Fprintln(w, " FORGE REQUIRES IPv6.<br>")
|
||||
fmt.Fprintln(w, " <br>")
|
||||
fmt.Fprintln(w, " bad url", badurl, "<a href=\"https://forge.wit.com/\">redirecting</a>")
|
||||
|
|
35
main.go
35
main.go
|
@ -4,10 +4,9 @@ import (
|
|||
"embed"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"go.wit.com/dev/alexflint/arg"
|
||||
"go.wit.com/lib/fhelp"
|
||||
"go.wit.com/lib/gui/prep"
|
||||
"go.wit.com/lib/protobuf/forgepb"
|
||||
"go.wit.com/log"
|
||||
|
@ -27,34 +26,32 @@ var LIBDIR string = "/var/lib/forged/" // need to deprecate this
|
|||
|
||||
func main() {
|
||||
me = new(mainType)
|
||||
prep.Bash(ARGNAME, argv.DoAutoComplete) // todo: this line should be: prep.Bash(argv)
|
||||
me.myGui = prep.Gui() // prepares the GUI package for go-args
|
||||
me.pp = arg.MustParse(&argv)
|
||||
me.myGui = prep.Gui() // prepares the GUI package for go-args
|
||||
me.auto = prep.Bash3(&argv) // this line should be: prep.Bash(&argv)
|
||||
|
||||
if argv.Hostname != "" {
|
||||
HOSTNAME = argv.Hostname
|
||||
}
|
||||
|
||||
// the default forged dir is /home/forge
|
||||
if os.Getenv("FORGE_GOSRC") == "" {
|
||||
os.Setenv("FORGE_GOSRC", "/home/forge")
|
||||
}
|
||||
|
||||
if os.Getenv("FORGE_PATCHDIR") == "" {
|
||||
os.Setenv("FORGE_PATCHDIR", "/var/lib/forged")
|
||||
}
|
||||
|
||||
me.forge = forgepb.RawInitPB()
|
||||
me.forge = forgepb.InitByAppname(ARGNAME)
|
||||
|
||||
if err := me.forge.InitPatchsets(); err != nil {
|
||||
log.Info("patches failed to open", err)
|
||||
badExit(err)
|
||||
}
|
||||
|
||||
if argv.List != nil {
|
||||
log.Printf("forge.Init() %s len()=%d\n", me.forge.Config.Filename, me.forge.Repos.Len())
|
||||
fhelp.DumpENV("finit:")
|
||||
me.forge.Config.DumpENV()
|
||||
doList()
|
||||
okExit("")
|
||||
}
|
||||
|
||||
if argv.Clean != nil {
|
||||
log.Printf("forge.Init() %s len()=%d\n", me.forge.Config.Filename, me.forge.Repos.Len())
|
||||
fhelp.DumpENV("finit:")
|
||||
me.forge.Config.DumpENV()
|
||||
doClean()
|
||||
okExit("")
|
||||
}
|
||||
|
||||
if argv.Merge != nil {
|
||||
if err := doMerge(); err != nil {
|
||||
badExit(err)
|
||||
|
|
|
@ -13,7 +13,9 @@ var me *mainType
|
|||
|
||||
// this app's variables
|
||||
type mainType struct {
|
||||
pp *arg.Parser // for parsing the command line args. Yay to alexf lint!
|
||||
forge *forgepb.Forge // for holding the forge protobuf files
|
||||
myGui *prep.GuiPrep // the gui toolkit handle
|
||||
pp *arg.Parser // for parsing the command line args. Yay to alexf lint!
|
||||
forge *forgepb.Forge // for holding the forge protobuf files
|
||||
myGui *prep.GuiPrep // the gui toolkit handle
|
||||
auto *prep.Auto // more experiments for bash handling
|
||||
configs *forgepb.ForgeConfigs // for holding the forge protobuf files
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue