Skip to content

Commit

Permalink
fix: pass api options
Browse files Browse the repository at this point in the history
  • Loading branch information
theredrad committed Sep 27, 2021
1 parent b0225ff commit a8cafdf
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ func init() {

flags.String("host", "127.0.0.1:8080", "host:port for the HTTP server")
flags.String("dir", "./images", "directory of images")
flags.String("cache", "true", "cache processed files")
flags.String("cdn", "", "cdn domain (works only on cache mode). leave empty to serve the files by app")
flags.String("min-width", "8", "minimum supported width")
flags.String("min-height", "8", "minimum supported height")
flags.String("max-width", "2000", "maximum supported width")
flags.String("max-height", "2000", "maximum supported height")

err := flags.Parse(os.Args[1:])
if err != nil {
Expand All @@ -41,7 +47,14 @@ func main() {

log.Printf("%d items loaded", m.Total())

a := api.New(m, &image.Imaging{}, nil)
a := api.New(m, &image.Imaging{}, &api.Options{
CacheFiles: viper.GetBool("cache"),
CDN: viper.GetString("cdn"),
MinWidth: viper.GetInt("min-width"),
MaxWidth: viper.GetInt("max-width"),
MinHeight: viper.GetInt("min-height"),
MaxHeight: viper.GetInt("max-height"),
})

r := mux.NewRouter()
r.HandleFunc("/image/{category}", a.SizeHandler).Methods(http.MethodGet)
Expand Down

0 comments on commit a8cafdf

Please sign in to comment.