106 lines
2.4 KiB
Go
106 lines
2.4 KiB
Go
package main
|
|
|
|
import (
|
|
"embed"
|
|
"fmt"
|
|
"net/http"
|
|
"os"
|
|
"time"
|
|
|
|
"go.wit.com/dev/alexflint/arg"
|
|
"go.wit.com/lib/gui/prep"
|
|
"go.wit.com/lib/protobuf/forgepb"
|
|
"go.wit.com/log"
|
|
)
|
|
|
|
// are sent via -ldflags at buildtime
|
|
var VERSION string
|
|
var BUILDTIME string
|
|
var ARGNAME string = "forged"
|
|
|
|
//go:embed resources/*
|
|
var resources embed.FS
|
|
|
|
var HOSTNAME string = "forge.wit.com"
|
|
var LIBDIR string = "/var/lib/forged/" // need to deprecate this
|
|
// var FORGEDIR string = "/home/forge" // deprecated?
|
|
|
|
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)
|
|
|
|
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 {
|
|
log.Info("patches failed to open", err)
|
|
}
|
|
|
|
if argv.List != nil {
|
|
doList()
|
|
okExit("")
|
|
}
|
|
|
|
if argv.Merge != nil {
|
|
if err := doMerge(); err != nil {
|
|
badExit(err)
|
|
}
|
|
okExit("")
|
|
}
|
|
|
|
if argv.Pull != nil {
|
|
log.Info("pull here")
|
|
okExit("")
|
|
}
|
|
|
|
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()
|
|
okHandlerFunc := http.HandlerFunc(okHandler)
|
|
|
|
// Set a limit of 50 kilobytes for requests to this handler.
|
|
// Adjust this value to your needs.
|
|
const maxUploadSize = 1025 * 1024 // 1 MB
|
|
mux.Handle("/", http.MaxBytesHandler(okHandlerFunc, maxUploadSize))
|
|
|
|
p := fmt.Sprintf(":%d", argv.Port)
|
|
log.Printf("Server starting on port %s...\n", p)
|
|
log.Printf("Test with: curl -d 'hello world' http://localhost:%s/\n", p)
|
|
|
|
server := &http.Server{
|
|
Addr: p,
|
|
Handler: mux,
|
|
ReadTimeout: 5 * time.Minute,
|
|
WriteTimeout: 10 * time.Second,
|
|
IdleTimeout: 120 * time.Second,
|
|
}
|
|
|
|
log.Printf("Server starting on port %s with a 1 MB request body limit...\n", p)
|
|
if err := server.ListenAndServe(); err != nil {
|
|
log.Fatal("Could not start server: %s\n", err)
|
|
}
|
|
okExit("")
|
|
}
|
|
|
|
log.Info("--daemon was not set. Just list the patches.")
|
|
// doList()
|
|
}
|