1
0

main.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. package main
  2. import (
  3. "context"
  4. "fmt"
  5. "log"
  6. "os"
  7. "os/signal"
  8. "syscall"
  9. "github.com/imgproxy/imgproxy/v3"
  10. "github.com/imgproxy/imgproxy/v3/version"
  11. "github.com/urfave/cli/v3"
  12. )
  13. // ver prints the imgproxy version and runs the main application
  14. func ver(ctx context.Context, c *cli.Command) error {
  15. fmt.Println(version.Version)
  16. return nil
  17. }
  18. // run starts the imgproxy server
  19. func run(ctx context.Context, cmd *cli.Command) error {
  20. // NOTE: for now, this flag is loaded in config.go package
  21. // presets := cmd.String("presets")
  22. if err := imgproxy.Init(); err != nil {
  23. return err
  24. }
  25. defer imgproxy.Shutdown()
  26. cfg, err := imgproxy.LoadConfigFromEnv(nil)
  27. if err != nil {
  28. return err
  29. }
  30. ctx, _ = signal.NotifyContext(ctx, syscall.SIGINT, syscall.SIGTERM)
  31. instance, err := imgproxy.New(ctx, cfg)
  32. if err != nil {
  33. return err
  34. }
  35. if err := instance.StartServer(ctx); 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: "presets",
  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. log.Fatal(err)
  66. }
  67. }