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 Systemd service file
|
||||
- Added installation script
|
||||
- Added command line option for config file
|
||||
|
||||
---
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ After=network.target
|
|||
[Service]
|
||||
ExecStart=/usr/local/bin/jilo-agent -c /usr/local/etc/jilo-agent.conf
|
||||
PIDFile=/run/jilo-agent.pid
|
||||
Restart=always
|
||||
Restart=on-failure
|
||||
SyslogIdentifier=jilo-agent
|
||||
User=root
|
||||
Group=root
|
||||
|
|
17
main.go
17
main.go
|
@ -12,6 +12,7 @@ Version: 0.1
|
|||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"encoding/json"
|
||||
"gopkg.in/yaml.v2"
|
||||
|
@ -290,8 +291,20 @@ func corsMiddleware(next http.Handler) http.Handler {
|
|||
// main sets up the http server and the routes
|
||||
func main() {
|
||||
|
||||
// load the configuration
|
||||
config := loadConfig("jilo-agent.conf")
|
||||
// Define a flag for the config file
|
||||
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)
|
||||
|
||||
mux := http.NewServeMux()
|
||||
|
|
Loading…
Reference in New Issue