Merge pull request #372 from mrd0ll4r/build-win

cmd/chihaya: make things work on windows
This commit is contained in:
mrd0ll4r 2017-12-24 13:28:29 +01:00 committed by GitHub
commit 8f472ad52c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 45 additions and 2 deletions

View file

@ -4,6 +4,7 @@ import (
"errors"
"os"
"os/signal"
"runtime"
"runtime/pprof"
"strings"
"syscall"
@ -141,8 +142,7 @@ func RunCmdFunc(cmd *cobra.Command, args []string) error {
quit := make(chan os.Signal)
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
reload := make(chan os.Signal)
signal.Notify(reload, syscall.SIGUSR1)
reload := makeReloadChan()
for {
select {
@ -173,6 +173,14 @@ func main() {
Short: "BitTorrent Tracker",
Long: "A customizable, multi-protocol BitTorrent Tracker",
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
noColors, err := cmd.Flags().GetBool("nocolors")
if err != nil {
return err
}
if noColors {
log.SetFormatter(&logrus.TextFormatter{DisableColors: true})
}
jsonLog, err := cmd.Flags().GetBool("json")
if err != nil {
return err
@ -216,6 +224,11 @@ func main() {
rootCmd.Flags().String("cpuprofile", "", "location to save a CPU profile")
rootCmd.Flags().Bool("debug", false, "enable debug logging")
rootCmd.Flags().Bool("json", false, "enable json logging")
if runtime.GOOS == "windows" {
rootCmd.Flags().Bool("nocolors", true, "disable log coloring")
} else {
rootCmd.Flags().Bool("nocolors", false, "disable log coloring")
}
if err := rootCmd.Execute(); err != nil {
log.Fatal("failed when executing root cobra command: " + err.Error())

View file

@ -0,0 +1,15 @@
// +build darwin freebsd linux netbsd openbsd dragonfly solaris
package main
import (
"os"
"os/signal"
"syscall"
)
func makeReloadChan() <-chan os.Signal {
reload := make(chan os.Signal)
signal.Notify(reload, syscall.SIGUSR1)
return reload
}

View file

@ -0,0 +1,15 @@
// +build windows
package main
import (
"os"
"os/signal"
"syscall"
)
func makeReloadChan() <-chan os.Signal {
reload := make(chan os.Signal)
signal.Notify(reload, syscall.SIGHUP)
return reload
}