Compare commits
21 Commits
Author | SHA1 | Date |
---|---|---|
|
460338c4eb | |
|
cd545c7c9f | |
|
b09b86009e | |
|
1f22b771c3 | |
|
ada923ea05 | |
|
2b6107fa51 | |
|
7a76b5acd1 | |
|
6df342bc10 | |
|
209ee29773 | |
|
43d653a8c0 | |
|
6722b019ec | |
|
82b232f47a | |
|
979fd2f978 | |
|
24e137c7ec | |
|
63be841469 | |
|
4827be1d2a | |
|
f1c1ca950c | |
|
7ea7393d6c | |
|
b9ec316d35 | |
|
c1de4f1f5a | |
|
34d9943e73 |
8
Makefile
8
Makefile
|
@ -1,10 +1,12 @@
|
||||||
.PHONY: build
|
.PHONY: build
|
||||||
|
|
||||||
VERSION = $(shell git describe --tags)
|
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
|
all: build
|
||||||
./forged list
|
FORGE_VERBOSE=true ./forged clean
|
||||||
|
# FORGE_VERBOSE=true ./forged list
|
||||||
|
|
||||||
build: goimports
|
build: goimports
|
||||||
GO111MODULE=off go build \
|
GO111MODULE=off go build \
|
||||||
|
|
98
argv.go
98
argv.go
|
@ -8,8 +8,12 @@ package main
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"go.wit.com/dev/alexflint/arg"
|
"go.wit.com/lib/gui/prep"
|
||||||
|
"go.wit.com/lib/gui/shell"
|
||||||
)
|
)
|
||||||
|
|
||||||
var argv args
|
var argv args
|
||||||
|
@ -17,62 +21,66 @@ var argv args
|
||||||
type args struct {
|
type args struct {
|
||||||
Pull *EmptyCmd `arg:"subcommand:pull" help:"'git pull' on the repos"`
|
Pull *EmptyCmd `arg:"subcommand:pull" help:"'git pull' on the repos"`
|
||||||
List *EmptyCmd `arg:"subcommand:list" help:"list 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"`
|
Merge *EmptyCmd `arg:"subcommand:merge" help:"merge in new patchsets"`
|
||||||
Init *EmptyCmd `arg:"subcommand:init" help:"init the repo list"`
|
Init *EmptyCmd `arg:"subcommand:init" help:"init the repo list"`
|
||||||
Port int `arg:"--port" default:"2520" help:"port to run on"`
|
Repos *EmptyCmd `arg:"subcommand:repos" help:"show the repos"`
|
||||||
Hostname string `arg:"--hostname" default:"forge.wit.com" help:"hostname to use"`
|
Port int `arg:"--port" default:"2520" help:"port to run on"`
|
||||||
Daemon bool `arg:"--daemon" help:"run as a daemon"`
|
Hostname string `arg:"--hostname" help:"hostname to use"`
|
||||||
Force bool `arg:"--force" help:"try to strong arm things"`
|
Daemon bool `arg:"--daemon" help:"run as a daemon"`
|
||||||
Verbose bool `arg:"--verbose" help:"show more output"`
|
Force bool `arg:"--force" help:"try to strong arm things"`
|
||||||
Bash bool `arg:"--bash" help:"generate bash completion"`
|
Verbose bool `arg:"--verbose" help:"show more output"`
|
||||||
BashAuto []string `arg:"--auto-complete" help:"todo: move this to go-arg"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type EmptyCmd struct {
|
type EmptyCmd struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (args) Appname() string {
|
||||||
|
return ARGNAME
|
||||||
|
}
|
||||||
|
|
||||||
func (args) Version() string {
|
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
|
return ARGNAME + " " + VERSION + " Built on " + BUILDTIME
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func (a args) DoAutoComplete(pb *prep.Auto) {
|
||||||
arg.MustParse(&argv)
|
switch pb.Cmd {
|
||||||
}
|
case "list":
|
||||||
|
pb.Autocomplete2("--missing")
|
||||||
// prints help to STDERR // TODO: move everything below this to go-args
|
case "clean":
|
||||||
func (args) doBashHelp() {
|
pb.Autocomplete2("")
|
||||||
if len(argv.BashAuto) < 2 {
|
|
||||||
fmt.Fprintf(os.Stderr, "something went wrong with the GO args autocomplete in %s\n", ARGNAME)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if argv.BashAuto[1] != "''" {
|
|
||||||
// if this is not blank, then the user has typed something
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if argv.BashAuto[0] != ARGNAME {
|
|
||||||
fmt.Fprintln(os.Stderr, argv.BashAuto[0])
|
|
||||||
// if this is not the name of the command, the user already started doing something
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if argv.BashAuto[0] == ARGNAME {
|
|
||||||
me.pp.WriteHelp(os.Stderr)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
fmt.Fprintln(os.Stderr, "")
|
|
||||||
fmt.Fprintln(os.Stderr, "something went wrong with the GO args package")
|
|
||||||
fmt.Fprintln(os.Stderr, "")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (args) doBashAuto() {
|
|
||||||
// argv.doBashHelp()
|
|
||||||
switch argv.BashAuto[0] {
|
|
||||||
case "merge":
|
|
||||||
fmt.Println("--force")
|
|
||||||
default:
|
default:
|
||||||
if argv.BashAuto[0] == ARGNAME {
|
pb.Autocomplete2("list clean")
|
||||||
// list the subcommands here
|
|
||||||
fmt.Println("list merge")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
os.Exit(0)
|
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
|
||||||
|
}
|
|
@ -0,0 +1,51 @@
|
||||||
|
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
|
||||||
|
// Use of this source code is governed by the GPL 3.0
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
// An app to submit patches for the 30 GO GUI repos
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"go.wit.com/gui"
|
||||||
|
"go.wit.com/lib/gadgets"
|
||||||
|
"go.wit.com/lib/gui/shell"
|
||||||
|
"go.wit.com/log"
|
||||||
|
)
|
||||||
|
|
||||||
|
func debug() {
|
||||||
|
defer func() {
|
||||||
|
if r := recover(); r != nil {
|
||||||
|
gui.Crash(r, "forge debug()")
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
time.Sleep(2 * time.Second)
|
||||||
|
for {
|
||||||
|
now := time.Now()
|
||||||
|
|
||||||
|
doList()
|
||||||
|
|
||||||
|
log.Printf("finished a scan here in (%s)\n", shell.FormatDuration(time.Since(now)))
|
||||||
|
time.Sleep(90 * time.Second)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func doGui() {
|
||||||
|
mainWindow := gadgets.NewGenericWindow("forged: forge.wit.com", "Current Settings")
|
||||||
|
mainWindow.Custom = func() {
|
||||||
|
log.Warn("MAIN WINDOW CLOSE")
|
||||||
|
now := time.Now()
|
||||||
|
log.Printf("rill repos.Reload() took (%s)\n", shell.FormatDuration(time.Since(now)))
|
||||||
|
okExit("")
|
||||||
|
}
|
||||||
|
drawWindow(mainWindow)
|
||||||
|
}
|
||||||
|
|
||||||
|
func drawWindow(win *gadgets.GenericWindow) {
|
||||||
|
grid := win.Group.RawGrid()
|
||||||
|
|
||||||
|
grid.NewButton("stats", func() {
|
||||||
|
doList()
|
||||||
|
})
|
||||||
|
}
|
20
doList.go
20
doList.go
|
@ -6,15 +6,27 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func doList() error {
|
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
|
// show all the patchsets with Names
|
||||||
for pset := range me.forge.Patchsets.IterAll() {
|
for pset := range me.forge.Patchsets.IterAll() {
|
||||||
log.Info("Info", pset.Name, pset.Uuid)
|
for patch := range pset.Patches.IterAll() {
|
||||||
for i, patch := range pset.Patches.Patches {
|
if patch.PatchId == "" {
|
||||||
log.Info("\t", i, patch.CommitHash, patch.Namespace)
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
18
doMerge.go
18
doMerge.go
|
@ -21,7 +21,7 @@ func doMerge() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func findAutoPatchset() *forgepb.Patchset {
|
func findAutoPatchset() *forgepb.Set {
|
||||||
for pset := range me.forge.Patchsets.IterAll() {
|
for pset := range me.forge.Patchsets.IterAll() {
|
||||||
if pset.Name == "forge auto commit" {
|
if pset.Name == "forge auto commit" {
|
||||||
return pset
|
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'")
|
log.Warn("findAutoPatchset() had to create 'forge auto commit'")
|
||||||
if fauto == nil {
|
if fauto == nil {
|
||||||
fauto = new(forgepb.Patchset)
|
fauto = new(forgepb.Set)
|
||||||
fauto.Name = "forge auto commit"
|
fauto.Name = "forge auto commit"
|
||||||
fauto.Patches = forgepb.NewPatches()
|
fauto.Patches = forgepb.NewPatches()
|
||||||
fauto.Uuid = uuid.New().String()
|
fauto.Uuid = uuid.New().String()
|
||||||
me.forge.Patchsets.Patchsets = append(me.forge.Patchsets.Patchsets, fauto)
|
me.forge.Patchsets.Append(fauto)
|
||||||
}
|
}
|
||||||
return fauto
|
return fauto
|
||||||
}
|
}
|
||||||
|
@ -63,7 +63,7 @@ func addRandomPatch(patch *forgepb.Patch) error {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
// adds a patchset or just the patches
|
// 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"
|
// if the name of the patchset is "forge auto commit"
|
||||||
// then just add all the patches
|
// then just add all the patches
|
||||||
if pb.Name == "forge auto commit" {
|
if pb.Name == "forge auto commit" {
|
||||||
|
@ -96,8 +96,8 @@ func addPatchset(filename string, pb *forgepb.Patchset) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clone() this protobuf into me.forge.Patchsets
|
// Clone() this protobuf into me.forge.Patchsets
|
||||||
var newpb *forgepb.Patchset
|
var newpb *forgepb.Set
|
||||||
newpb = proto.Clone(pb).(*forgepb.Patchset)
|
newpb = proto.Clone(pb).(*forgepb.Set)
|
||||||
if newpb != nil {
|
if newpb != nil {
|
||||||
me.forge.Patchsets.Patchsets = append(me.forge.Patchsets.Patchsets, newpb)
|
me.forge.Patchsets.Patchsets = append(me.forge.Patchsets.Patchsets, newpb)
|
||||||
}
|
}
|
||||||
|
@ -122,8 +122,8 @@ func mergePatchsets() {
|
||||||
fmt.Println(entry.Name(), err)
|
fmt.Println(entry.Name(), err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
var p *forgepb.Patchset
|
var p *forgepb.Set
|
||||||
p = new(forgepb.Patchset)
|
p = new(forgepb.Set)
|
||||||
err = p.Unmarshal(bytes)
|
err = p.Unmarshal(bytes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(entry.Name(), err)
|
fmt.Println(entry.Name(), err)
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
"go.wit.com/lib/protobuf/forgepb"
|
"go.wit.com/lib/protobuf/forgepb"
|
||||||
"go.wit.com/lib/protobuf/httppb"
|
"go.wit.com/lib/protobuf/httppb"
|
||||||
|
"go.wit.com/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
func addNewPatches(pb *forgepb.Patches, reqPB *httppb.HttpRequest) *forgepb.Patches {
|
func addNewPatches(pb *forgepb.Patches, reqPB *httppb.HttpRequest) *forgepb.Patches {
|
||||||
|
@ -11,6 +14,7 @@ func addNewPatches(pb *forgepb.Patches, reqPB *httppb.HttpRequest) *forgepb.Patc
|
||||||
me.forge.AddNewPatch(newpatch)
|
me.forge.AddNewPatch(newpatch)
|
||||||
newPatchesPB.Append(newpatch)
|
newPatchesPB.Append(newpatch)
|
||||||
}
|
}
|
||||||
|
reqPB.Logf("Recived %d patches from client", newPatchesPB.Len())
|
||||||
return newPatchesPB
|
return newPatchesPB
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,28 +38,24 @@ func sendPendingPatches(pb *forgepb.Patches, reqPB *httppb.HttpRequest) *forgepb
|
||||||
return allPatchesPB
|
return allPatchesPB
|
||||||
}
|
}
|
||||||
|
|
||||||
func sendPendingPatchsets(pb *forgepb.Patchsets, reqPB *httppb.HttpRequest) *forgepb.Patchsets {
|
func sendPendingPatchsets(pb *forgepb.Sets, reqPB *httppb.HttpRequest) *forgepb.Sets {
|
||||||
allPatchsetsPB := new(forgepb.Patchsets)
|
allPatchsetsPB := new(forgepb.Sets)
|
||||||
for pset := range me.forge.Patchsets.IterAll() {
|
for pset := range me.forge.Patchsets.IterAll() {
|
||||||
allPatchsetsPB.Append(pset)
|
allPatchsetsPB.Append(pset)
|
||||||
}
|
}
|
||||||
return allPatchsetsPB
|
return allPatchsetsPB
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeReposPB(reqPB *httppb.HttpRequest) (*gitpb.Repos, error) {
|
/*
|
||||||
pb := gitpb.NewRepos()
|
|
||||||
err := pb.Unmarshal(reqPB.ServerData)
|
|
||||||
return pb, err
|
|
||||||
}
|
|
||||||
|
|
||||||
func makePatchesPB(reqPB *httppb.HttpRequest) (*forgepb.Patches, error) {
|
func makePatchesPB(reqPB *httppb.HttpRequest) (*forgepb.Patches, error) {
|
||||||
pb := forgepb.NewPatches()
|
pb := forgepb.NewPatches()
|
||||||
err := pb.Unmarshal(reqPB.ServerData)
|
err := pb.Unmarshal(reqPB.ServerData)
|
||||||
return pb, err
|
return pb, err
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
func makePatchsetsPB(reqPB *httppb.HttpRequest) (*forgepb.Patchsets, error) {
|
func makePatchsetsPB(reqPB *httppb.HttpRequest) (*forgepb.Sets, error) {
|
||||||
pb := forgepb.NewPatchsets()
|
pb := forgepb.NewSets()
|
||||||
err := pb.Unmarshal(reqPB.ServerData)
|
err := pb.Unmarshal(reqPB.ServerData)
|
||||||
return pb, err
|
return pb, err
|
||||||
}
|
}
|
||||||
|
|
239
http.go
239
http.go
|
@ -2,7 +2,6 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
@ -12,62 +11,22 @@ import (
|
||||||
"go.wit.com/log"
|
"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) {
|
func logReqPB(pb *httppb.HttpRequest) {
|
||||||
log.Info("LOG: httppb.HttpRequest START:")
|
log.Info("LOG: httppb.HttpRequest START:")
|
||||||
for i, line := range strings.Join(pb.Log, "\n") {
|
for i, line := range pb.Logs {
|
||||||
log.Infof("\t%d %s\n", i, line)
|
log.Infof("%d, URL:%s LINE: %s\n", int(i), pb.URL, line)
|
||||||
}
|
}
|
||||||
log.Info("LOG: httppb.HttpRequest END")
|
log.Info("LOG: httppb.HttpRequest END")
|
||||||
}
|
}
|
||||||
|
|
||||||
func okHandler(w http.ResponseWriter, r *http.Request) {
|
func okHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
reqPB, err := httppb.ReqToPB(r)
|
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 {
|
if err != nil {
|
||||||
log.Info("something crazy err", err)
|
reqPB.Logf("httppb err %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
who := whoSent(r)
|
|
||||||
|
|
||||||
route := reqPB.Route
|
route := reqPB.Route
|
||||||
parts := strings.Split(route, "?")
|
|
||||||
requrl := parts[0]
|
|
||||||
|
|
||||||
if route == "/" {
|
if route == "/" {
|
||||||
w.Header().Set("Content-Type", "text")
|
w.Header().Set("Content-Type", "text")
|
||||||
|
@ -76,33 +35,75 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// used for uptime monitor checking
|
|
||||||
if route == "/uptime" {
|
|
||||||
writeFile(w, "uptime.html")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Warn("forged REQUEST URL =", requrl, "from =", who)
|
|
||||||
|
|
||||||
if strings.HasPrefix(route, "/repos/") {
|
if strings.HasPrefix(route, "/repos/") {
|
||||||
pb, err := makeReposPB(reqPB)
|
pb := gitpb.NewRepos()
|
||||||
if err != nil {
|
if err := pb.Unmarshal(reqPB.ClientData); err == nil {
|
||||||
reqPB.Log = append(reqPB.Log, log.Sprintf("%v", err))
|
reqPB.Logf("Repos Unmarshal() len=%d", pb.Len())
|
||||||
|
} else {
|
||||||
|
reqPB.Logf("Repos Unmarshal() err=%v", err)
|
||||||
}
|
}
|
||||||
result := gitpb.NewRepos()
|
result := gitpb.NewRepos()
|
||||||
switch route {
|
switch route {
|
||||||
case "/repos/check":
|
case "/repos/check":
|
||||||
result = addRequest(pb, reqPB)
|
result = addRequest(pb, reqPB)
|
||||||
log.Infof("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":
|
case "/repos/pull":
|
||||||
result = pullRequest(pb, reqPB)
|
result = pullRequest(pb, reqPB)
|
||||||
case "/repos/add":
|
case "/repos/add":
|
||||||
result = addRequest(pb, reqPB)
|
result = addRequest(pb, reqPB)
|
||||||
default:
|
default:
|
||||||
|
reqPB.Logf("repos check result.Len()=%d pb.Len()=%d", result.Len(), pb.Len())
|
||||||
log.Info("repos", route, "unknown")
|
log.Info("repos", route, "unknown")
|
||||||
}
|
}
|
||||||
if err := result.SendReply(w, reqPB); err != nil {
|
if err := result.SendReply(w, reqPB); err != nil {
|
||||||
log.Info("Oh well, Send to client failed. err =", 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)
|
// todo: logReq(reqPB)
|
||||||
logReqPB(reqPB)
|
logReqPB(reqPB)
|
||||||
|
@ -110,20 +111,21 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if strings.HasPrefix(route, "/patches/") {
|
if strings.HasPrefix(route, "/patches/") {
|
||||||
pb, err := makePatchesPB(reqPB)
|
pb := forgepb.NewPatches()
|
||||||
if err != nil {
|
if err := pb.Unmarshal(reqPB.ClientData); err == nil {
|
||||||
reqPB.Log = append(reqPB.Log, log.Sprintf("%v", err))
|
reqPB.Logf("Patches Unmarshal() len=%d", pb.Len())
|
||||||
|
} else {
|
||||||
|
reqPB.Logf("Patches Unmarshal() err=%v", err)
|
||||||
}
|
}
|
||||||
result := forgepb.NewPatches()
|
result := forgepb.NewPatches()
|
||||||
switch route {
|
switch route {
|
||||||
case "/patches/new":
|
case "/patches/new":
|
||||||
result = addNewPatches(pb, reqPB)
|
result = addNewPatches(pb, reqPB)
|
||||||
log.Infof("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":
|
case "/patches/applied":
|
||||||
log.Info("not really anything needs to be done on applied patches?")
|
reqPB.Log("not really anything needs to be done on applied patches?")
|
||||||
// result = handleAppliedPatches(pb, reqPB)
|
|
||||||
case "/patches/merged":
|
case "/patches/merged":
|
||||||
log.Info("a maintainer has merged these patches")
|
reqPB.Log("a maintainer has merged these patches")
|
||||||
result = handleMergedPatches(pb, reqPB)
|
result = handleMergedPatches(pb, reqPB)
|
||||||
// result = handleAppliedPatches(pb, reqPB)
|
// result = handleAppliedPatches(pb, reqPB)
|
||||||
case "/patches/get":
|
case "/patches/get":
|
||||||
|
@ -132,7 +134,7 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
result = addNewPatches(pb, reqPB)
|
result = addNewPatches(pb, reqPB)
|
||||||
}
|
}
|
||||||
if err := result.SendReply(w, reqPB); err != nil {
|
if err := result.SendReply(w, reqPB); err != nil {
|
||||||
log.Info("Oh well, Send to client failed. err =", err)
|
reqPB.Logf("Oh well, Send to client failed. err=%v", err)
|
||||||
}
|
}
|
||||||
me.forge.SavePatchsets()
|
me.forge.SavePatchsets()
|
||||||
// todo: logReq(reqPB)
|
// todo: logReq(reqPB)
|
||||||
|
@ -143,9 +145,9 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
if strings.HasPrefix(route, "/patchsets/") {
|
if strings.HasPrefix(route, "/patchsets/") {
|
||||||
pb, err := makePatchsetsPB(reqPB)
|
pb, err := makePatchsetsPB(reqPB)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
reqPB.Log = append(reqPB.Log, log.Sprintf("%v", err))
|
reqPB.Logf("%v", err)
|
||||||
}
|
}
|
||||||
result := forgepb.NewPatchsets()
|
result := forgepb.NewSets()
|
||||||
switch route {
|
switch route {
|
||||||
case "/patches/get":
|
case "/patches/get":
|
||||||
result = sendPendingPatchsets(pb, reqPB)
|
result = sendPendingPatchsets(pb, reqPB)
|
||||||
|
@ -163,107 +165,30 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
logReqPB(reqPB)
|
logReqPB(reqPB)
|
||||||
|
|
||||||
/*
|
// used for uptime monitor checking
|
||||||
if route == "/lookup" {
|
if route == "/uptime" {
|
||||||
log.Info("doing lookup len(reqPB.Body) =", len(reqPB.Body))
|
httppb.WriteFile(w, resources, "uptime.html")
|
||||||
found, err := lookupRepos(reqPB.Body)
|
return
|
||||||
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" {
|
if route == "/goReference.svg" {
|
||||||
w.Header().Set("Content-Type", "image/svg+xml")
|
w.Header().Set("Content-Type", "image/svg+xml")
|
||||||
writeFile(w, "goReference.svg")
|
httppb.WriteFile(w, resources, "goReference.svg")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if route == "/skeleton.v2.css" {
|
if route == "/skeleton.v2.css" {
|
||||||
writeFile(w, "skeleton.v2.css")
|
httppb.WriteFile(w, resources, "skeleton.v2.css")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if route == "/favicon.ico" {
|
if route == "/favicon.ico" {
|
||||||
writeFile(w, "ipv6.png")
|
httppb.WriteFile(w, resources, "ipv6.png")
|
||||||
return
|
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())
|
badurl(w, r.URL.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
func writeFile(w http.ResponseWriter, filename string) {
|
func writeFile(w http.ResponseWriter, filename string) {
|
||||||
// fmt.Fprintln(w, "GOT TEST?")
|
// fmt.Fprintln(w, "GOT TEST?")
|
||||||
fullname := "resources/" + filename
|
fullname := "resources/" + filename
|
||||||
|
@ -277,8 +202,8 @@ func writeFile(w http.ResponseWriter, filename string) {
|
||||||
var repohtml string
|
var repohtml string
|
||||||
repohtml = string(pfile)
|
repohtml = string(pfile)
|
||||||
fmt.Fprintln(w, repohtml)
|
fmt.Fprintln(w, repohtml)
|
||||||
// log.Println("writeFile() found internal file:", filename)
|
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
func badurl(w http.ResponseWriter, badurl string) {
|
func badurl(w http.ResponseWriter, badurl string) {
|
||||||
fmt.Fprintln(w, "<!DOCTYPE html>")
|
fmt.Fprintln(w, "<!DOCTYPE html>")
|
||||||
|
@ -287,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, " <meta http-equiv=\"refresh\" content=\"3; url=https://"+HOSTNAME+"/\">")
|
||||||
fmt.Fprintln(w, " </head>")
|
fmt.Fprintln(w, " </head>")
|
||||||
fmt.Fprintln(w, " <body>")
|
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, " FORGE REQUIRES IPv6.<br>")
|
||||||
fmt.Fprintln(w, " <br>")
|
fmt.Fprintln(w, " <br>")
|
||||||
fmt.Fprintln(w, " bad url", badurl, "<a href=\"https://forge.wit.com/\">redirecting</a>")
|
fmt.Fprintln(w, " bad url", badurl, "<a href=\"https://forge.wit.com/\">redirecting</a>")
|
||||||
|
|
117
main.go
117
main.go
|
@ -4,12 +4,10 @@ import (
|
||||||
"embed"
|
"embed"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"go.wit.com/dev/alexflint/arg"
|
|
||||||
"go.wit.com/gui"
|
|
||||||
"go.wit.com/lib/fhelp"
|
"go.wit.com/lib/fhelp"
|
||||||
|
"go.wit.com/lib/gui/prep"
|
||||||
"go.wit.com/lib/protobuf/forgepb"
|
"go.wit.com/lib/protobuf/forgepb"
|
||||||
"go.wit.com/log"
|
"go.wit.com/log"
|
||||||
)
|
)
|
||||||
|
@ -28,42 +26,32 @@ var LIBDIR string = "/var/lib/forged/" // need to deprecate this
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
me = new(mainType)
|
me = new(mainType)
|
||||||
gui.InitArg()
|
me.myGui = prep.Gui() // prepares the GUI package for go-args
|
||||||
me.pp = arg.MustParse(&argv)
|
me.auto = prep.Bash3(&argv) // this line should be: prep.Bash(&argv)
|
||||||
|
|
||||||
if argv.Bash {
|
me.forge = forgepb.InitByAppname(ARGNAME)
|
||||||
fhelp.DoBash(ARGNAME)
|
|
||||||
os.Exit(0)
|
|
||||||
}
|
|
||||||
if len(argv.BashAuto) != 0 {
|
|
||||||
argv.doBashAuto()
|
|
||||||
os.Exit(0)
|
|
||||||
}
|
|
||||||
|
|
||||||
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()
|
|
||||||
|
|
||||||
if err := me.forge.InitPatchsets(); err != nil {
|
if err := me.forge.InitPatchsets(); err != nil {
|
||||||
log.Info("patches failed to open", err)
|
log.Info("patches failed to open", err)
|
||||||
|
badExit(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if argv.List != nil {
|
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()
|
doList()
|
||||||
okExit("")
|
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 argv.Merge != nil {
|
||||||
if err := doMerge(); err != nil {
|
if err := doMerge(); err != nil {
|
||||||
badExit(err)
|
badExit(err)
|
||||||
|
@ -77,6 +65,11 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if argv.Daemon == true {
|
if argv.Daemon == true {
|
||||||
|
if argv.Gui != nil {
|
||||||
|
me.myGui.Start() // loads the GUI toolkit
|
||||||
|
doGui() // start making our forge GUI
|
||||||
|
debug() // sits here forever
|
||||||
|
}
|
||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
okHandlerFunc := http.HandlerFunc(okHandler)
|
okHandlerFunc := http.HandlerFunc(okHandler)
|
||||||
|
|
||||||
|
@ -104,74 +97,6 @@ func main() {
|
||||||
okExit("")
|
okExit("")
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
// --- Best Practice: Create a custom http.Server ---
|
|
||||||
server := &http.Server{
|
|
||||||
Addr: p,
|
|
||||||
Handler: mux,
|
|
||||||
|
|
||||||
// ReadTimeout is the total time to read the entire request, including the body.
|
|
||||||
// Increase this to a value that can accommodate your largest expected uploads.
|
|
||||||
// For example, 5 minutes.
|
|
||||||
ReadTimeout: 5 * time.Minute,
|
|
||||||
|
|
||||||
// WriteTimeout is the maximum duration before timing out writes of the response.
|
|
||||||
WriteTimeout: 10 * time.Second,
|
|
||||||
|
|
||||||
// IdleTimeout is the maximum amount of time to wait for the
|
|
||||||
// next request when keep-alives are enabled.
|
|
||||||
IdleTimeout: 120 * time.Second,
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
log.Println(argv.Version(), "HOSTNAME set to:", HOSTNAME)
|
|
||||||
log.Println("Running on port", "http://localhost"+p)
|
|
||||||
log.Println("Running on port", "http://localhost"+p+"/ipv6.png")
|
|
||||||
// if err := http.ListenAndServe(p, nil); err != nil {
|
|
||||||
if err := server.ListenAndServe(); err != nil {
|
|
||||||
log.Fatalf("Could not start server: %s\n", err)
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
log.Info("Running in --daemon mode")
|
|
||||||
http.HandleFunc("/", okHandler)
|
|
||||||
// go https() // use caddy instead
|
|
||||||
p := fmt.Sprintf(":%d", argv.Port)
|
|
||||||
log.Println(argv.Version(), "HOSTNAME set to:", HOSTNAME)
|
|
||||||
log.Println("Running on port", "http://localhost"+p)
|
|
||||||
log.Println("Running on port", "http://localhost"+p+"/ipv6.png")
|
|
||||||
err := http.ListenAndServe(p, nil)
|
|
||||||
if err != nil {
|
|
||||||
log.Println("Error starting server:", err)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
log.Info("--daemon was not set. Just list the patches.")
|
log.Info("--daemon was not set. Just list the patches.")
|
||||||
// doList()
|
// doList()
|
||||||
}
|
}
|
||||||
|
|
||||||
func formatDuration(d time.Duration) string {
|
|
||||||
seconds := int(d.Seconds()) % 60
|
|
||||||
minutes := int(d.Minutes()) % 60
|
|
||||||
hours := int(d.Hours()) % 24
|
|
||||||
days := int(d.Hours()) / 24
|
|
||||||
|
|
||||||
result := ""
|
|
||||||
if days > 0 {
|
|
||||||
result += fmt.Sprintf("%dd ", days)
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
if hours > 0 {
|
|
||||||
result += fmt.Sprintf("%dh ", hours)
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
if minutes > 0 {
|
|
||||||
result += fmt.Sprintf("%dm ", minutes)
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
if seconds > 0 {
|
|
||||||
result += fmt.Sprintf("%ds", seconds)
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"go.wit.com/dev/alexflint/arg"
|
"go.wit.com/dev/alexflint/arg"
|
||||||
|
"go.wit.com/lib/gui/prep"
|
||||||
"go.wit.com/lib/protobuf/forgepb"
|
"go.wit.com/lib/protobuf/forgepb"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -12,7 +13,9 @@ var me *mainType
|
||||||
|
|
||||||
// this app's variables
|
// this app's variables
|
||||||
type mainType struct {
|
type mainType struct {
|
||||||
pp *arg.Parser // for parsing the command line args. Yay to alexf lint!
|
pp *arg.Parser // for parsing the command line args. Yay to alexf lint!
|
||||||
forge *forgepb.Forge // for holding the forge protobuf files
|
forge *forgepb.Forge // for holding the forge protobuf files
|
||||||
// myGui *gui.Node // the gui toolkit handle
|
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