the beginning of something

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-10-12 00:17:26 -05:00
parent b689239cd3
commit 5fcb83a1a2
5 changed files with 113 additions and 15 deletions

View File

@ -7,7 +7,7 @@ REDOMOD = $(shell if [ -e go.sum ]; then echo go.sum exists; else GO111MODULE=
all:
GO111MODULE=off go build -v -ldflags "-X main.Version=${VERSION} -X gui.GUIVERSION=${VERSION}"
./virtigo --version
./virtigo --hosts farm01,farm02,farm03
./virtigo --hosts farm01 farm02 farm03
# this is for release builds using the go.mod files
release-build:
@ -33,4 +33,5 @@ clean:
git-clone:
go-clone --recursive --go-src --no-work go.wit.com/apps/go-clone
go-clone --recursive --go-src --no-work go.wit.com/apps/virtigo
go-clone --recursive --go-src --no-work go.wit.com/apps/gowebd
go-clone --recursive --go-src --no-work go.wit.com/lib/daemons/virtigod

12
argv.go
View File

@ -6,21 +6,19 @@ package main
this enables command line options from other packages like 'gui' and 'log'
*/
var argv args
type args struct {
DryRun bool `arg:"--dry-run" help:"show what would be run"`
Uptime bool `arg:"--uptime" help:"enable port 8080 for use with uptime checks like Kuma"`
Hosts []string `arg:"--hosts" help:"hosts to connect to"`
Uptime bool `arg:"--uptime" default:"true" help:"allow uptime checks for things like Kuma"`
Port int `arg:"--port" default:"8080" help:"specify a different default port"`
}
func (a args) Description() string {
return `
virtigo will help control your cluster of hypervisiors
Install:
apt install virtigo
Sources:
go-clone --recursive --no-work -go-src go.wit.com/apps/virtigo
go install go.wit.com/apps/virtigo@latest
`
}

90
http.go Normal file
View File

@ -0,0 +1,90 @@
package main
import (
"fmt"
"net/http"
"strings"
"go.wit.com/lib/gui/shell"
"go.wit.com/log"
)
// remove '?' part and trailing '/'
func cleanURL(url string) string {
url = "/" + strings.Trim(url, "/")
return url
}
func okHandler(w http.ResponseWriter, r *http.Request) {
var tmp string
tmp = cleanURL(r.URL.Path)
log.Info("Got URL:", tmp)
if tmp == "/" {
fmt.Fprintln(w, "OK")
return
}
if tmp == "/me" {
fmt.Fprintln(w, "OK")
return
}
if tmp == "/vms" {
s := shell.Wget("http://wilddog:2520/vms")
var bytesSplice []byte
bytesSplice = s.Bytes()
fmt.Fprintln(w, string(bytesSplice))
return
}
if tmp == "/favicon.ico" {
writeFile(w, "ipv6.png")
return
}
if tmp == "/uptime" {
writeFile(w, "uptime.html")
return
}
// used for uptime monitor checking (like Kuma)
if tmp == "/uptime" {
writeFile(w, "uptime.html")
return
}
log.Warn("BAD URL =", tmp)
fmt.Fprintln(w, "BAD ZOOT")
// badurl(w, r.URL.String())
// fmt.Fprintln(w, "BAD", tmp)
}
func writeFile(w http.ResponseWriter, filename string) {
// fmt.Fprintln(w, "GOT TEST?")
fullname := "resources/" + filename
pfile, err := resources.ReadFile(fullname)
if err != nil {
log.Println("ERROR:", err)
// w.Write(pfile)
return
}
var repohtml string
repohtml = string(pfile)
if filename == "goReference.svg" {
w.Header().Set("Content-Type", "image/svg+xml")
}
fmt.Fprintln(w, repohtml)
log.Println("writeFile() found internal file:", filename)
}
// starts and sits waiting for HTTP requests
func startHTTP() {
http.HandleFunc("/", okHandler)
p := fmt.Sprintf(":%d", argv.Port)
log.Println("Running on port", p)
err := http.ListenAndServe(p, nil)
if err != nil {
log.Println("Error starting server:", err)
}
}

20
main.go
View File

@ -3,23 +3,31 @@
package main
import (
// "log"
// "log"
"embed"
"os"
"go.wit.com/log"
"go.wit.com/dev/alexflint/arg"
"go.wit.com/log"
)
var Version string
var myargs args
//go:embed resources/*
var resources embed.FS
func main() {
pp := arg.MustParse(&myargs)
pp := arg.MustParse(&argv)
if myargs.Uptime {
if ! argv.Uptime {
pp.WriteHelp(os.Stdout)
os.Exit(0)
}
log.Info("connect to cluser here", myargs.Hosts)
log.Info("connect to cluser here", argv.Hosts)
for i, s := range argv.Hosts {
log.Info("i, s =", i, s)
}
startHTTP()
}

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 6.3 KiB