2020-06-21 12:33:43 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2021-08-05 20:19:25 +02:00
|
|
|
"os"
|
|
|
|
"time"
|
2020-06-21 12:33:43 +02:00
|
|
|
|
2021-08-06 08:29:57 +02:00
|
|
|
"github.com/efekarakus/termcolor"
|
2021-04-28 16:15:45 +02:00
|
|
|
"github.com/juanfont/headscale/cmd/headscale/cli"
|
2023-04-27 16:57:11 +02:00
|
|
|
"github.com/pkg/profile"
|
2021-08-05 20:19:25 +02:00
|
|
|
"github.com/rs/zerolog"
|
|
|
|
"github.com/rs/zerolog/log"
|
2020-06-21 12:33:43 +02:00
|
|
|
)
|
|
|
|
|
2021-04-25 17:24:42 +02:00
|
|
|
func main() {
|
2023-04-27 16:57:11 +02:00
|
|
|
if _, enableProfile := os.LookupEnv("HEADSCALE_PROFILING_ENABLED"); enableProfile {
|
|
|
|
if profilePath, ok := os.LookupEnv("HEADSCALE_PROFILING_PATH"); ok {
|
|
|
|
err := os.MkdirAll(profilePath, os.ModePerm)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal().Err(err).Msg("failed to create profiling directory")
|
|
|
|
}
|
|
|
|
|
|
|
|
defer profile.Start(profile.ProfilePath(profilePath)).Stop()
|
|
|
|
} else {
|
|
|
|
defer profile.Start().Stop()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-06 08:29:57 +02:00
|
|
|
var colors bool
|
|
|
|
switch l := termcolor.SupportLevel(os.Stderr); l {
|
|
|
|
case termcolor.Level16M:
|
|
|
|
colors = true
|
|
|
|
case termcolor.Level256:
|
|
|
|
colors = true
|
|
|
|
case termcolor.LevelBasic:
|
|
|
|
colors = true
|
2021-11-14 17:52:55 +01:00
|
|
|
case termcolor.LevelNone:
|
|
|
|
colors = false
|
2021-08-06 08:29:57 +02:00
|
|
|
default:
|
|
|
|
// no color, return text as is.
|
|
|
|
colors = false
|
|
|
|
}
|
|
|
|
|
|
|
|
// Adhere to no-color.org manifesto of allowing users to
|
|
|
|
// turn off color in cli/services
|
|
|
|
if _, noColorIsSet := os.LookupEnv("NO_COLOR"); noColorIsSet {
|
|
|
|
colors = false
|
|
|
|
}
|
|
|
|
|
2021-08-05 20:19:25 +02:00
|
|
|
zerolog.TimeFieldFormat = zerolog.TimeFormatUnix
|
|
|
|
log.Logger = log.Output(zerolog.ConsoleWriter{
|
2023-08-11 17:52:03 +02:00
|
|
|
Out: os.Stderr,
|
2021-08-05 20:19:25 +02:00
|
|
|
TimeFormat: time.RFC3339,
|
2021-08-06 08:29:57 +02:00
|
|
|
NoColor: !colors,
|
2021-08-05 20:19:25 +02:00
|
|
|
})
|
|
|
|
|
2021-07-25 15:14:09 +02:00
|
|
|
cli.Execute()
|
2021-02-21 01:30:03 +01:00
|
|
|
}
|