forked from hiroksarker/statuz
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
51 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,61 @@ | ||
package main | ||
|
||
import ( | ||
"errors" | ||
"github.com/prometheus/client_golang/prometheus/promhttp" | ||
"github.com/statuzproj/statuz/utils/evictedconf" | ||
"github.com/statuzproj/statuz/utils/healthz" | ||
"log" | ||
"net/http" | ||
"sync" | ||
) | ||
|
||
// | ||
//func main() { | ||
// var wg sync.WaitGroup | ||
// | ||
// // Start the HTTP server in a goroutine | ||
// wg.Add(1) | ||
// go func() { | ||
// defer wg.Done() | ||
// | ||
// http.HandleFunc("/healthz", healthz.HealthCheck) | ||
// http.Handle("/metrics", promhttp.Handler()) | ||
// err := http.ListenAndServe(":8080", nil) | ||
// if err != nil { | ||
// log.Fatalf("HTTP server error: %v", err) | ||
// } | ||
// }() | ||
// | ||
// // Start the watcher in another goroutine | ||
// wg.Add(1) | ||
// go func() { | ||
// defer wg.Done() | ||
// | ||
// err := start() | ||
// if err != nil { | ||
// log.Fatalf("Error starting watcher: %v", err) | ||
// } | ||
// }() | ||
// | ||
// // Wait for all goroutines to complete before exiting | ||
// wg.Wait() | ||
//} | ||
// | ||
//func start() error { | ||
// env, err := evictedconf.GetEnvVars() | ||
// if err != nil { | ||
// return err | ||
// } | ||
// | ||
// if env.Type == "webpage" { | ||
// err := watchPage(env.Endpoint, env.Interval) | ||
// if err != nil { | ||
// return err | ||
// } | ||
// } else if env.Type == "ip" { | ||
// watchIp(env.Endpoint, env.Port, env.Interval) | ||
// } else { | ||
// return errors.New("Unsupported watch type: " + env.Type) | ||
// } | ||
// return nil | ||
//} | ||
|
||
func main() { | ||
log.Println("Work in Progress!!") | ||
http.HandleFunc("/healthz", healthz.HealthCheck) | ||
http.ListenAndServe(":8080", nil) | ||
var wg sync.WaitGroup | ||
|
||
// Start the HTTP server in a goroutine | ||
wg.Add(1) | ||
go func() { | ||
defer wg.Done() | ||
|
||
http.HandleFunc("/healthz", healthz.HealthCheck) | ||
http.Handle("/metrics", promhttp.Handler()) | ||
err := http.ListenAndServe(":8080", nil) | ||
if err != nil { | ||
log.Fatalf("HTTP server error: %v", err) | ||
} | ||
}() | ||
|
||
// Start the watcher in another goroutine | ||
wg.Add(1) | ||
go func() { | ||
defer wg.Done() | ||
|
||
err := start() | ||
if err != nil { | ||
log.Fatalf("Error starting watcher: %v", err) | ||
} | ||
}() | ||
|
||
// Wait for all goroutines to complete before exiting | ||
wg.Wait() | ||
} | ||
|
||
func start() error { | ||
env, err := evictedconf.GetEnvVars() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if env.Type == "webpage" { | ||
err := watchPage(env.Endpoint, env.Interval) | ||
if err != nil { | ||
return err | ||
} | ||
} else if env.Type == "ip" { | ||
watchIp(env.Endpoint, env.Port, env.Interval) | ||
} else { | ||
return errors.New("Unsupported watch type: " + env.Type) | ||
} | ||
return nil | ||
} |