From 879ee5004f079880ce02fd2193bc2829b387ba54 Mon Sep 17 00:00:00 2001 From: Yasen Pramatarov Date: Tue, 3 Sep 2024 10:23:44 +0300 Subject: [PATCH] Switches to YAML for config file --- go/build.sh | 19 ++++++++++++++++++- go/go.mod | 5 +++++ go/go.sum | 3 +++ go/jilo-agent.conf | 15 +++++++++++++++ go/jilo-agent.json | 6 ------ go/main.go | 17 +++++++++-------- 6 files changed, 50 insertions(+), 15 deletions(-) create mode 100644 go/go.mod create mode 100644 go/go.sum create mode 100644 go/jilo-agent.conf delete mode 100644 go/jilo-agent.json diff --git a/go/build.sh b/go/build.sh index 0747d1d..d459111 100755 --- a/go/build.sh +++ b/go/build.sh @@ -1,3 +1,20 @@ #!/usr/bin/env bash -go build -o jilo-agent main.go +### +# Jilo Agent building script +# +# Description: Building script for Jilo Agent +# Author: Yasen Pramatarov +# License: GPLv2 +# Project URL: https://lindeas.com/jilo +# Year: 2024 +# Version: 0.1 +# +# requirements: +# - go +# - upx +### + +CGO_ENABLED=0 go build -trimpath -ldflags="-s -w" -o jilo-agent main.go +upx --best --lzma -o jilo-agent-upx jilo-agent +mv jilo-agent-upx jilo-agent diff --git a/go/go.mod b/go/go.mod new file mode 100644 index 0000000..14bff77 --- /dev/null +++ b/go/go.mod @@ -0,0 +1,5 @@ +module jilo-agent + +go 1.22.6 + +require gopkg.in/yaml.v2 v2.4.0 // indirect diff --git a/go/go.sum b/go/go.sum new file mode 100644 index 0000000..7534661 --- /dev/null +++ b/go/go.sum @@ -0,0 +1,3 @@ +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= diff --git a/go/jilo-agent.conf b/go/jilo-agent.conf new file mode 100644 index 0000000..9400db0 --- /dev/null +++ b/go/jilo-agent.conf @@ -0,0 +1,15 @@ +## +# configuration file for Jilo Agent +## + +# the port on which the agent will listen +agent_port: 8081 + +# the port we check for nginx +nginx_port: 80 + +# URL to the Jicofo stats API +jicofo_stats_url: "http://localhost:8888/stats" + +# URL to the JVB stats API +jvb_stats_url: "http://localhost:8080/colibri/stats" diff --git a/go/jilo-agent.json b/go/jilo-agent.json deleted file mode 100644 index 7800538..0000000 --- a/go/jilo-agent.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "agent_port": 8081, - "nginx_port": 80, - "jicofo_stats_url": "http://localhost:8888/stats", - "jvb_stats_url": "http://localhost:8080/colibri/stats" -} diff --git a/go/main.go b/go/main.go index c0797cc..af966f3 100644 --- a/go/main.go +++ b/go/main.go @@ -14,6 +14,7 @@ package main import ( "encoding/json" "fmt" + "gopkg.in/yaml.v2" "io/ioutil" "log" "net/http" @@ -25,11 +26,11 @@ import ( // Config holds the structure of the configuration file type Config struct { - AgentPort int `json:"agent_port"` - NginxPort int `json:"nginx_port"` - ProsodyPort int `json:"prosody_port"` - JicofoStatsURL string `json:"jicofo_stats_url"` - JVBStatsURL string `json:"jvb_stats_url"` + AgentPort int `yaml:"agent_port"` + NginxPort int `yaml:"nginx_port"` + ProsodyPort int `yaml:"prosody_port"` + JicofoStatsURL string `yaml:"jicofo_stats_url"` + JVBStatsURL string `yaml:"jvb_stats_url"` } // NginxData holds the nginx data structure for the API response to /nginx @@ -103,7 +104,7 @@ func getJitsiAPIData(service string, url string) map[string]interface{} { return result } -// loadConfig loads the configuration from a JSON config file +// loadConfig loads the configuration from a YAML config file func loadConfig(filename string) (Config) { // default config values @@ -129,7 +130,7 @@ func loadConfig(filename string) (Config) { return config } - if err := json.Unmarshal(bytes, &config); err != nil { + if err := yaml.Unmarshal(bytes, &config); err != nil { log.Printf("Error parsing the config file. Using default values.") } @@ -181,7 +182,7 @@ func jvbHandler(config Config, w http.ResponseWriter, r *http.Request) { func main() { // load the configuration - config := loadConfig("jilo-agent.json") + config := loadConfig("jilo-agent.conf") // endpoints http.HandleFunc("/nginx", func(w http.ResponseWriter, r *http.Request) {