does linting on docker build/ci now
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -2,36 +2,35 @@ package process
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/signal"
|
||||
"time"
|
||||
|
||||
"github.com/k0kubun/pp"
|
||||
"github.com/mattn/go-isatty"
|
||||
"github.com/rs/zerolog"
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/spf13/viper"
|
||||
"os"
|
||||
"time"
|
||||
)
|
||||
|
||||
// CLIEntry is the main entrypoint
|
||||
func CLIEntry(version string, buildarch string) int {
|
||||
|
||||
func CLIEntry(version, buildarch string) int {
|
||||
hp := new(HistoryPoster)
|
||||
hp.version = version
|
||||
hp.buildarch = buildarch
|
||||
hp.startup = time.Now()
|
||||
|
||||
c := make(chan os.Signal, 1)
|
||||
signal.Notify(hp.shutdownChannel, os.Interrupt)
|
||||
signal.Notify(c, os.Interrupt)
|
||||
|
||||
hp.configure()
|
||||
hp.setupLogging()
|
||||
hp.setupDatabase()
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
go func() {
|
||||
// this sits and waits for an interrupt to be received
|
||||
sig := <-c
|
||||
log.Info().Msgf("signal received: %+v", sig)
|
||||
// FIXME this might need to be scoped to a specific signal
|
||||
cancel()
|
||||
}()
|
||||
return hp.runForever(ctx)
|
||||
@@ -43,12 +42,40 @@ type HistoryPoster struct {
|
||||
startup time.Time
|
||||
}
|
||||
|
||||
func (hp *HistoryPoster) runForever(ctx context.Context) int {
|
||||
func (hp *HistoryPoster) configure() {
|
||||
viper.SetConfigName("historyposter")
|
||||
viper.SetConfigType("yaml")
|
||||
viper.AddConfigPath("/etc/historyposter") // path to look for the config file in
|
||||
viper.AddConfigPath("$HOME/.config/historyposter") // call multiple times to add many search paths
|
||||
|
||||
viper.SetEnvPrefix("HISTORYPOSTER")
|
||||
viper.AutomaticEnv()
|
||||
|
||||
viper.SetDefault("Debug", false)
|
||||
|
||||
if err := viper.ReadInConfig(); err != nil {
|
||||
if _, ok := err.(viper.ConfigFileNotFoundError); ok {
|
||||
// Config file not found; ignore error if desired
|
||||
} else {
|
||||
// Config file was found but another error was produced
|
||||
log.Panic().
|
||||
Err(err).
|
||||
Msg("cannot read config file")
|
||||
}
|
||||
}
|
||||
|
||||
if viper.GetBool("debug") {
|
||||
pp.Print(viper.AllSettings())
|
||||
}
|
||||
}
|
||||
|
||||
func (hp *HistoryPoster) runForever(ctx context.Context) int {
|
||||
<-ctx.Done()
|
||||
log.Info().Msgf("shutting down")
|
||||
return 0
|
||||
}
|
||||
|
||||
func (hp *HistoryPoster) setupLogging() {
|
||||
|
||||
log.Logger = log.With().Caller().Logger()
|
||||
|
||||
tty := isatty.IsTerminal(os.Stdin.Fd()) || isatty.IsCygwinTerminal(os.Stdin.Fd())
|
||||
|
||||
Reference in New Issue
Block a user