Commit 0147e360 authored by zdc's avatar zdc

added command flag -data (config and template directory)

parent 2590a360
package main
import (
"flag"
"fmt"
"html/template"
"log"
......@@ -10,6 +11,9 @@ import (
"golang.org/x/crypto/ssh"
)
// where is config and template
var datapath string
// declare variables for page template
type DataOut struct {
OutputHeader, OutputBody string
......@@ -127,7 +131,7 @@ func SSHRun (router_ip, port, username, password, command, argument string) Data
// show page and base logic
func ShowPage (w http.ResponseWriter, r *http.Request) {
// select html template
t, _ := template.ParseFiles("page_main.gtpl")
t, _ := template.ParseFiles(datapath+"/page_main.gtpl")
// check HTTP method
if r.Method == "POST" {
var action, argument string
......@@ -191,9 +195,12 @@ func ShowPage (w http.ResponseWriter, r *http.Request) {
func main() {
// set config
flag.StringVar(&datapath, "data", "", "data directory")
flag.Parse()
viper.SetConfigName("config")
viper.SetConfigType("toml")
viper.AddConfigPath(".")
viper.AddConfigPath(datapath)
errconfig := viper.ReadInConfig() // Find and read the config file
if errconfig != nil { // Handle errors reading the config file
panic(fmt.Errorf("Fatal error config file: %s \n", errconfig))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment