mirror of
https://github.com/byReqz/probehost2.git
synced 2024-11-21 22:33:14 +00:00
add basic cli flags
This commit is contained in:
parent
8b1b28b274
commit
dcb8ad72e3
16
main.go
16
main.go
@ -6,6 +6,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net"
|
"net"
|
||||||
|
"flag"
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
@ -13,13 +14,20 @@ import (
|
|||||||
var logstdout = log.New()
|
var logstdout = log.New()
|
||||||
var logfile = log.New()
|
var logfile = log.New()
|
||||||
|
|
||||||
|
var logfilepath string
|
||||||
|
var listenport int
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
flag.StringVar(&logfilepath, "logfilepath", "probehost2.log", "sets the output file for the log")
|
||||||
|
flag.IntVar(&listenport, "port", 8000, "sets the port to listen on")
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
logstdout.SetFormatter(&log.TextFormatter{
|
logstdout.SetFormatter(&log.TextFormatter{
|
||||||
FullTimestamp: true})
|
FullTimestamp: true})
|
||||||
logstdout.SetOutput(os.Stdout)
|
logstdout.SetOutput(os.Stdout)
|
||||||
logstdout.SetLevel(log.InfoLevel)
|
logstdout.SetLevel(log.InfoLevel)
|
||||||
|
|
||||||
logpath, err := os.OpenFile("probehost2.log", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0660)
|
logpath, err := os.OpenFile(logfilepath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0660)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logstdout.Fatal("Failed to initialize the logfile: ", err.Error())
|
logstdout.Fatal("Failed to initialize the logfile: ", err.Error())
|
||||||
}
|
}
|
||||||
@ -106,7 +114,7 @@ func main() {
|
|||||||
http.HandleFunc("/ping/", ping)
|
http.HandleFunc("/ping/", ping)
|
||||||
http.HandleFunc("/mtr/", mtr)
|
http.HandleFunc("/mtr/", mtr)
|
||||||
http.HandleFunc("/", showhelp)
|
http.HandleFunc("/", showhelp)
|
||||||
logstdout.Info("Serving on :8000")
|
logstdout.Info("Serving on :", listenport)
|
||||||
logfile.Info("Serving on :8000")
|
logfile.Info("Serving on :", listenport)
|
||||||
http.ListenAndServe(":8000", nil)
|
http.ListenAndServe(fmt.Sprint(":", listenport), nil)
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user