From 0c8dc3669745a0062c4ab6aee36a72aa923e0407 Mon Sep 17 00:00:00 2001 From: "Alexander \"Arav\" Andreev" Date: Sun, 2 Jan 2022 02:56:46 +0400 Subject: [PATCH] Moving other source code files into prog package. Renaming processes.json to config.json. --- main.go | 9 +++++---- confguration.go => prog/confguration.go | 2 +- errors.go => prog/errors.go | 2 +- processlist.go => prog/processlist.go | 2 +- server.go => prog/server.go | 6 +++--- 5 files changed, 11 insertions(+), 10 deletions(-) rename confguration.go => prog/confguration.go (99%) rename errors.go => prog/errors.go (98%) rename processlist.go => prog/processlist.go (99%) rename server.go => prog/server.go (95%) diff --git a/main.go b/main.go index 22e457b..e24e8ca 100644 --- a/main.go +++ b/main.go @@ -22,6 +22,7 @@ package main import ( "flag" "fmt" + . "httpprocwatchd/prog" "log" "os" "os/exec" @@ -56,8 +57,8 @@ func main() { log.SetFlags(0) - flag.StringVar(&oConfigPath, "config", "processes.json", "path to configuration file") - flag.StringVar(&oConfigPath, "c", "processes.json", "path to configuration file (shorthand)") + flag.StringVar(&oConfigPath, "config", "config.json", "path to configuration file") + flag.StringVar(&oConfigPath, "c", "config.json", "path to configuration file (shorthand)") flag.BoolVar(&oShowVersion, "version", false, "show version") flag.BoolVar(&oShowVersion, "v", false, "show version (shorthand)") @@ -124,7 +125,7 @@ func main() { return } - srv := createAndStartHTTPServer(conf) + srv := CreateAndStartHTTPServer(conf) syssignal := make(chan os.Signal, 1) signal.Notify(syssignal, os.Interrupt, syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP) @@ -137,7 +138,7 @@ func main() { fallthrough case syscall.SIGINT | syscall.SIGTERM: log.Println("Shutting down... ") - shutdownHTTPServer(srv) + ShutdownHTTPServer(srv) log.Println("Server shutted down.") os.Exit(0) case syscall.SIGHUP: diff --git a/confguration.go b/prog/confguration.go similarity index 99% rename from confguration.go rename to prog/confguration.go index 4632b17..c621b8a 100644 --- a/confguration.go +++ b/prog/confguration.go @@ -17,7 +17,7 @@ along with this program. If not, see . */ -package main +package prog import ( "encoding/json" diff --git a/errors.go b/prog/errors.go similarity index 98% rename from errors.go rename to prog/errors.go index be1ef36..45592f4 100644 --- a/errors.go +++ b/prog/errors.go @@ -17,7 +17,7 @@ along with this program. If not, see . */ -package main +package prog import "errors" diff --git a/processlist.go b/prog/processlist.go similarity index 99% rename from processlist.go rename to prog/processlist.go index 8d1a5f7..af94af6 100644 --- a/processlist.go +++ b/prog/processlist.go @@ -17,7 +17,7 @@ along with this program. If not, see . */ -package main +package prog import ( "encoding/xml" diff --git a/server.go b/prog/server.go similarity index 95% rename from server.go rename to prog/server.go index bcab470..31228ba 100644 --- a/server.go +++ b/prog/server.go @@ -17,7 +17,7 @@ along with this program. If not, see . */ -package main +package prog import ( "context" @@ -28,7 +28,7 @@ import ( "time" ) -func createAndStartHTTPServer(conf *Configuration) *http.Server { +func CreateAndStartHTTPServer(conf *Configuration) *http.Server { router := http.NewServeMux() router.HandleFunc("/processes", AreProcessesUp(&conf.Processes)) @@ -49,7 +49,7 @@ func createAndStartHTTPServer(conf *Configuration) *http.Server { return srv } -func shutdownHTTPServer(srv *http.Server) { +func ShutdownHTTPServer(srv *http.Server) { ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel()