//go:generate go install github.com/valyala/quicktemplate/qtc@master //go:generate qtc -dir=web //go:generate go install golang.org/x/text/cmd/gotext@master //go:generate gotext -srclang=en update -lang=en,ru,eo -out=locales_gen.go package main import ( "context" "embed" "flag" "io/fs" "log" "os" "os/signal" "path/filepath" "runtime" "runtime/pprof" "syscall" "github.com/caarlos0/env/v10" "source.toby3d.me/toby3d/pay/internal/cmd/pay" "source.toby3d.me/toby3d/pay/internal/domain" ) //go:embed web/static/* var static embed.FS func main() { logger := log.New(os.Stdout, "pay\t", log.LstdFlags) static, err := fs.Sub(static, filepath.Join("web", "static")) if err != nil { logger.Fatalln(err) } cpuProfilePath := flag.String("cpuprofile", "", "set path to saving CPU memory profile") memProfilePath := flag.String("memprofile", "", "set path to saving pprof memory profile") flag.Parse() config := new(domain.Config) if err = env.ParseWithOptions(config, env.Options{Prefix: "PAY_"}); err != nil { logger.Fatalln(err) } app := pay.New(logger, static, *config) done := make(chan os.Signal, 1) signal.Notify(done, os.Interrupt, syscall.SIGINT, syscall.SIGTERM) if *cpuProfilePath != "" { var cpuProfile *os.File if cpuProfile, err = os.Create(*cpuProfilePath); err != nil { logger.Fatalln("could not create CPU profile:", err) } defer cpuProfile.Close() if err = pprof.StartCPUProfile(cpuProfile); err != nil { logger.Fatalln("could not start CPU profile:", err) } defer pprof.StopCPUProfile() } go app.Run() <-done if err = app.Stop(context.Background()); err != nil { logger.Fatalln(err) } if *memProfilePath == "" { return } memProfile, err := os.Create(*memProfilePath) if err != nil { logger.Fatalln("could not create memory profile:", err) } defer memProfile.Close() runtime.GC() // NOTE(toby3d): get up-to-date statistics if err = pprof.WriteHeapProfile(memProfile); err != nil { logger.Fatalln("could not write memory profile:", err) } }