Skip to content

Commit

Permalink
bring back old code
Browse files Browse the repository at this point in the history
  • Loading branch information
timam committed Oct 23, 2023
1 parent d59feb9 commit 56cb4e5
Showing 1 changed file with 51 additions and 54 deletions.
105 changes: 51 additions & 54 deletions svc/watcher/main.go
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
}

0 comments on commit 56cb4e5

Please sign in to comment.