//go:build client

package main

import (
	"context"
	"time"

	"github.com/prometheus/client_golang/prometheus/promhttp"
	"repositories.action2quare.com/ayo/gocommon/flagx"
	"repositories.action2quare.com/ayo/gocommon/logger"
	"repositories.action2quare.com/ayo/houston/client"

	"net/http"
)

func main() {
	flagx.Parse()

	hc, err := client.NewClient(true)
	if err != nil {
		panic(err)
	}

	http.Handle("/metrics", promhttp.Handler())
	server := &http.Server{Addr: ":9100", Handler: nil}

	go func() {
		logger.Println("listen /metrics")
		err := server.ListenAndServe()
		if err != nil {
			logger.Error(err)
		}
	}()

	hc.Start()
	ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)

	server.Shutdown(ctx)
	cancel()
}
