From 3e77935b7ba60e7778a0b929e60753d7fa621eca Mon Sep 17 00:00:00 2001 From: Rudra Sarkar Date: Mon, 22 Aug 2022 04:59:44 +0600 Subject: [PATCH] fixed few issue --- README.md | 11 +++-------- checkenv.go | 3 ++- main.go | 2 +- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 24c487c..11af934 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ ## PortMonitor -It requires HackerTarget API and monitor port using [cron library](github.com/robfig/cron/v3), and it requires mongodb to store data and slack webhook. +It requires HackerTarget API and monitor port using cronjob, and it requires mongodb to store data and slack webhook. ### MongoDB Compose file @@ -34,16 +34,11 @@ services: ### Environment -Change HackerTarget API also mongodb URI and finally slack webhook. +Change HackerTarget API also mongodb URI and finally slack webhook. Create folder on `mkdir $HOME/.portmonitor/` and +then create a file `touch $HOME/.portmonitor/.env` follow the example env and change with yours. ```dotenv HACKERTARGET_API=7xxxxxsomerandomstringsd1c MONGODB_URI=mongodb://root:example@localhost:27017/ SLACK_WEBHOOK=https://hooks.slack.com/services/xxxx/xxx/xxxxx ``` - - -### Todo - -- [ ] Add cronjob to add monitoring system -- [ ] Add a env item for specify the cron time \ No newline at end of file diff --git a/checkenv.go b/checkenv.go index 7d80836..353bf00 100644 --- a/checkenv.go +++ b/checkenv.go @@ -3,10 +3,11 @@ package main import ( "github.com/joho/godotenv" "github.com/thep0y/go-logger/log" + "os" ) func checkDotEnv() bool { - if err := godotenv.Load(".env"); err != nil { + if err := godotenv.Load(os.ExpandEnv("$HOME/.portmonitor/.env")); err != nil { log.Fatal("No .env file found") } diff --git a/main.go b/main.go index b5db3ab..793872f 100644 --- a/main.go +++ b/main.go @@ -9,10 +9,10 @@ import ( ) func main() { - URI := os.Getenv("MONGODB_URI") if checkDotEnv() { log.Fatal("environment file not found") } else { + URI := os.Getenv("MONGODB_URI") defer config.IsConnected(URI).Disconnect(context.TODO()) output.GetOutput() }