1
0

main.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. package main
  2. import (
  3. "context"
  4. "fmt"
  5. "os"
  6. "os/signal"
  7. "syscall"
  8. "github.com/imgproxy/imgproxy/v3"
  9. "github.com/imgproxy/imgproxy/v3/logger"
  10. optionsparser "github.com/imgproxy/imgproxy/v3/options/parser"
  11. "github.com/imgproxy/imgproxy/v3/version"
  12. "github.com/urfave/cli/v3"
  13. )
  14. // ver prints the imgproxy version and runs the main application
  15. func ver(ctx context.Context, c *cli.Command) error {
  16. fmt.Println(version.Version)
  17. return nil
  18. }
  19. // run starts the imgproxy server
  20. func run(ctx context.Context, cmd *cli.Command) error {
  21. if err := imgproxy.Init(); err != nil {
  22. return err
  23. }
  24. defer imgproxy.Shutdown()
  25. cfg, err := imgproxy.LoadConfigFromEnv(nil)
  26. if err != nil {
  27. return err
  28. }
  29. ctx, _ = signal.NotifyContext(ctx, syscall.SIGINT, syscall.SIGTERM)
  30. instance, err := imgproxy.New(ctx, cfg)
  31. if err != nil {
  32. return err
  33. }
  34. defer instance.Close(ctx)
  35. if err := instance.StartServer(ctx, nil); err != nil {
  36. return err
  37. }
  38. return nil
  39. }
  40. func main() {
  41. cmd := &cli.Command{
  42. Name: "imgproxy",
  43. Usage: "Fast and secure standalone server for resizing and converting remote images",
  44. Flags: []cli.Flag{
  45. &cli.StringFlag{
  46. Name: optionsparser.PresetsFlagName,
  47. Usage: "path of the file with presets",
  48. },
  49. },
  50. Action: run,
  51. Commands: []*cli.Command{
  52. {
  53. Name: "version",
  54. Usage: "print the version",
  55. Action: ver,
  56. },
  57. {
  58. Name: "health",
  59. Usage: "perform a healthcheck on a running imgproxy instance",
  60. Action: healthcheck,
  61. },
  62. },
  63. }
  64. if err := cmd.Run(context.Background(), os.Args); err != nil {
  65. logger.Fatal(err.Error())
  66. }
  67. }