try to rename as gowebd

put the HTML assets raw in the binary also
	I'm how old and still committed a binary. squashed

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-10-08 11:36:46 -05:00
parent c6be85e92f
commit d827c398f0
13 changed files with 78 additions and 26 deletions

1
.gitignore vendored
View File

@ -3,4 +3,5 @@ go.mod
go.sum go.sum
go.wit.com go.wit.com
gowebd
files/ files/

View File

@ -1,3 +1,5 @@
VERSION = $(shell git describe --tags)
all: all:
@echo "make run # will build and run the daemon here" @echo "make run # will build and run the daemon here"
@echo "make debian # will build a debian package" @echo "make debian # will build a debian package"
@ -19,9 +21,9 @@ restart:
run: run:
git pull git pull
echo "build it!" echo "build it!"
GO111MODULE=off go build -v -x GO111MODULE=off go build -v -x -ldflags "-X main.Version=${VERSION} -X gui.GUIVERSION=${VERSION}"
./go.wit.com ./gowebd --port 2233
# setcap 'cap_net_bind_service=+ep' go.wit.com # allow the binary to open ports below 1024 # setcap 'cap_net_bind_service=+ep' gowebd # allow the binary to open ports below 1024
goimports: goimports:
goimports -w *.go goimports -w *.go
@ -31,6 +33,11 @@ redomod:
GO111MODULE= go mod init GO111MODULE= go mod init
GO111MODULE= go mod tidy GO111MODULE= go mod tidy
clean:
rm -f go.*
rm -f go.wit.com
rm -f gowebd
# makes a .deb package # makes a .deb package
debian: debian:
go-deb --no-gui --repo go.wit.com/apps/go.wit.com go-deb --no-gui --repo go.wit.com/apps/gowebd

3
README Normal file
View File

@ -0,0 +1,3 @@
makes the website go.wit.com
TODO: make it generic so it can use different DNS names

12
args.go
View File

@ -10,11 +10,17 @@ import (
"go.wit.com/dev/alexflint/arg" "go.wit.com/dev/alexflint/arg"
) )
var args struct { var argv args
type args struct {
ListRepos bool `arg:"--list-repos" help:"list all repositories"` ListRepos bool `arg:"--list-repos" help:"list all repositories"`
Port int `arg:"--port" help:"port to run on (default is 2520)"` Port int `arg:"--port" default:"2520" help:"port to run on"`
}
func (args) Version() string {
return "virtigo " + Version
} }
func init() { func init() {
arg.MustParse(&args) arg.MustParse(&argv)
} }

5
build
View File

@ -7,9 +7,10 @@ cp gowebd.service files/lib/systemd/system/
# caddy file. propose this as the dir structure caddy should use # caddy file. propose this as the dir structure caddy should use
mkdir -p files/etc/gowebd/ mkdir -p files/etc/gowebd/
cp Caddyfile.go.wit.com files/etc/gowebd/ cp Caddyfile.go.wit.com files/etc/gowebd/
cp resources/repomap files/etc/gowebd/ cp resources/Makefile files/etc/gowebd/
# share dir # share dir
mkdir -p files/usr/share/gowebd/ mkdir -p files/usr/share/gowebd/
cp Makefile files/usr/share/gowebd/ cp Makefile files/usr/share/gowebd/
cp resources/repomap files/usr/share/gowebd/go.wit.com cp -a resources/repomap files/usr/share/gowebd/go.wit.com
cp -a resources files/usr/share/gowebd/

View File

@ -1,6 +1,6 @@
Source: go.wit.com Source: gowebd
Build-Depends: golang Build-Depends: golang
Package: go.wit.com Package: gowebd
Maintainer: Jeff Carr <jcarr@wit.com> Maintainer: Jeff Carr <jcarr@wit.com>
Architecture: amd64 Architecture: amd64
Depends: caddy Depends: caddy

View File

@ -1,13 +1,13 @@
[Unit] [Unit]
Description=go.wit.com Description=gowebd
[Service] [Service]
User=root User=root
Type=simple Type=simple
ExecStart=/usr/bin/go.wit.com ExecStart=/usr/bin/gowebd
ExecStop=killall go.wit.com ExecStop=killall gowebd
Restart=on-failure Restart=on-failure
RestartSec=30 RestartSec=5
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target

17
main.go
View File

@ -11,6 +11,8 @@ import (
"go.wit.com/log" "go.wit.com/log"
) )
var Version string
//go:embed resources/* //go:embed resources/*
var resources embed.FS var resources embed.FS
@ -21,6 +23,8 @@ var versionMap map[string]string
var configfile []string var configfile []string
var keysSorted []string var keysSorted []string
var HOSTNAME string = "go.wit.com"
// remove '?' part and trailing '/' // remove '?' part and trailing '/'
func cleanURL(url string) string { func cleanURL(url string) string {
url = "/" + strings.Trim(url, "/") url = "/" + strings.Trim(url, "/")
@ -38,7 +42,7 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
requrl := parts[0] requrl := parts[0]
url, repourl := findkey(requrl) url, repourl := findkey(requrl)
log.Warn("go.wit.com URL =", url, "REPO URL =", repourl, "REQUEST URL =", requrl) log.Warn("gowebd URL =", url, "REPO URL =", repourl, "REQUEST URL =", requrl)
if repourl != "" { if repourl != "" {
repoHTML(w, url, repourl) repoHTML(w, url, repourl)
return return
@ -96,6 +100,10 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
writeFile(w, "skeleton.v2.css") writeFile(w, "skeleton.v2.css")
return return
} }
if tmp == "/favicon.ico" {
writeFile(w, "ipv6.png")
return
}
// used for uptime monitor checking // used for uptime monitor checking
if tmp == "/uptime" { if tmp == "/uptime" {
writeFile(w, "uptime.html") writeFile(w, "uptime.html")
@ -150,7 +158,10 @@ func main() {
log.Println("found log =", versionMap["go.wit.com/log"]) log.Println("found log =", versionMap["go.wit.com/log"])
http.HandleFunc("/", okHandler) http.HandleFunc("/", okHandler)
// go https() // go https()
err := http.ListenAndServe(":2520", nil) p := fmt.Sprintf(":%d", argv.Port)
log.Println("HOSTNAME set to:", HOSTNAME)
log.Println("Running on port", p)
err := http.ListenAndServe(p, nil)
if err != nil { if err != nil {
log.Println("Error starting server:", err) log.Println("Error starting server:", err)
} }
@ -160,7 +171,7 @@ func badurl(w http.ResponseWriter, badurl string) {
fmt.Fprintln(w, "<!DOCTYPE html>") fmt.Fprintln(w, "<!DOCTYPE html>")
fmt.Fprintln(w, "<html>") fmt.Fprintln(w, "<html>")
fmt.Fprintln(w, " <head>") fmt.Fprintln(w, " <head>")
fmt.Fprintln(w, " <meta http-equiv=\"refresh\" content=\"3; url=https://go.wit.com/\">") 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 IS NOT SUPPORTED<br>")

View File

@ -5,4 +5,4 @@ cd /etc/gowebd/
ln -s /usr/share/gowebd/go.wit.com . ln -s /usr/share/gowebd/go.wit.com .
# allow the binary to open ports below 1024 # allow the binary to open ports below 1024
setcap 'cap_net_bind_service=+ep' /usr/bin/go.wit.com setcap 'cap_net_bind_service=+ep' /usr/bin/gowebd

View File

@ -64,11 +64,19 @@ func findkey(url string) (string, string) {
} }
func readconfigfile() { func readconfigfile() {
var pfile []byte
var err error
repoMap = make(map[string]string) repoMap = make(map[string]string)
pfile, err := resources.ReadFile("resources/repomap")
pfile, err = os.ReadFile("/etc/gowebd/repomap")
if err != nil { if err != nil {
log.Error(err, "missing repomap in the binary") log.Error(err, "no repository map file found in /etc/gowebd/")
return log.Error(err, "falling back to the repository map file built into the gowebd binary")
pfile, err = resources.ReadFile("resources/repomap")
if err != nil {
log.Error(err, "missing repomap in the binary")
return
}
} }
configfile = strings.Split(string(pfile), "\n") configfile = strings.Split(string(pfile), "\n")
for _, line := range configfile { for _, line := range configfile {

19
resources/Makefile Normal file
View File

@ -0,0 +1,19 @@
all:
gowebd --version
@echo "make log # watch gowebd log"
@echo "make restart # restart gowebd"
@echo "make enable # enable gowebd on boot"
@echo "make status # show the systemd status of gowebd"
log:
@journalctl -f -xeu gowebd.service
status:
systemctl status gowebd.service
enable:
systemctl enable gowebd.service
restart:
systemctl stop gowebd.service
systemctl start gowebd.service

View File

@ -1,4 +0,0 @@
#!/bin/bash -x
#
echo "TODO: make this work"

BIN
resources/ipv6.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB