Adds command line option for config file
parent
a49f16c584
commit
0743113cef
|
@ -18,6 +18,7 @@ All notable changes to this project will be documented in this file.
|
||||||
- Added SysV init script
|
- Added SysV init script
|
||||||
- Added Systemd service file
|
- Added Systemd service file
|
||||||
- Added installation script
|
- Added installation script
|
||||||
|
- Added command line option for config file
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ After=network.target
|
||||||
[Service]
|
[Service]
|
||||||
ExecStart=/usr/local/bin/jilo-agent -c /usr/local/etc/jilo-agent.conf
|
ExecStart=/usr/local/bin/jilo-agent -c /usr/local/etc/jilo-agent.conf
|
||||||
PIDFile=/run/jilo-agent.pid
|
PIDFile=/run/jilo-agent.pid
|
||||||
Restart=always
|
Restart=on-failure
|
||||||
SyslogIdentifier=jilo-agent
|
SyslogIdentifier=jilo-agent
|
||||||
User=root
|
User=root
|
||||||
Group=root
|
Group=root
|
||||||
|
|
17
main.go
17
main.go
|
@ -12,6 +12,7 @@ Version: 0.1
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"gopkg.in/yaml.v2"
|
"gopkg.in/yaml.v2"
|
||||||
|
@ -290,8 +291,20 @@ func corsMiddleware(next http.Handler) http.Handler {
|
||||||
// main sets up the http server and the routes
|
// main sets up the http server and the routes
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
// load the configuration
|
// Define a flag for the config file
|
||||||
config := loadConfig("jilo-agent.conf")
|
configFile := flag.String("c", "./jilo-agent.conf", "Specify the agent config file")
|
||||||
|
|
||||||
|
// Parse the flags
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
|
// Check if the file exists, fallback to default config file if not
|
||||||
|
if _, err := os.Stat(*configFile); os.IsNotExist(err) {
|
||||||
|
fmt.Println("Config file not found, using default values")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Load the configuration from the specified file (option -c) or the default config file name
|
||||||
|
config := loadConfig(*configFile)
|
||||||
|
|
||||||
secretKey = []byte(config.SecretKey)
|
secretKey = []byte(config.SecretKey)
|
||||||
|
|
||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
|
|
Loading…
Reference in New Issue