Renamed collector, aggregator to api server, api folder to agent (#133)

* Renamed aggregator -> apiServer.

* Format errors with container names.

* Renamed collector -> apiServer.

* Rephrased help messages.

* Moved api -> agent.

* Continue renameing api -> agent in Makefile and Dockerfiles.
This commit is contained in:
nimrod-up9
2021-07-22 17:17:17 +03:00
committed by GitHub
parent a2150b4a78
commit 803681a239
45 changed files with 75 additions and 76 deletions

61
agent/pkg/utils/utils.go Normal file
View File

@@ -0,0 +1,61 @@
package utils
import (
"github.com/gofiber/fiber/v2"
"github.com/romana/rlog"
"log"
"net/url"
"os"
"os/signal"
"reflect"
"syscall"
)
// StartServer starts the server with a graceful shutdown
func StartServer(app *fiber.App) {
signals := make(chan os.Signal, 2)
signal.Notify(signals,
os.Interrupt, // this catch ctrl + c
syscall.SIGTSTP, // this catch ctrl + z
)
go func() {
_ = <-signals
rlog.Infof("Shutting down...")
_ = app.Shutdown()
}()
// Run server.
if err := app.Listen(":8899"); err != nil {
log.Printf("Oops... Server is not running! Reason: %v", err)
}
}
func ReverseSlice(data interface{}) {
value := reflect.ValueOf(data)
valueLen := value.Len()
for i := 0; i <= int((valueLen-1)/2); i++ {
reverseIndex := valueLen - 1 - i
tmp := value.Index(reverseIndex).Interface()
value.Index(reverseIndex).Set(value.Index(i))
value.Index(i).Set(reflect.ValueOf(tmp))
}
}
func CheckErr(e error) {
if e != nil {
log.Printf("%v", e)
//panic(e)
}
}
func SetHostname(address, newHostname string) string {
replacedUrl, err := url.Parse(address)
if err != nil{
log.Printf("error replacing hostname to %s in address %s, returning original %v",newHostname, address, err)
return address
}
replacedUrl.Host = newHostname
return replacedUrl.String()
}