diff --git a/main.go b/main.go index 21e8664..9aa10e5 100644 --- a/main.go +++ b/main.go @@ -1,10 +1,6 @@ package main import ( - "github.com/gorilla/handlers" - "github.com/gorilla/mux" - "github.com/spf13/pflag" - "github.com/spf13/viper" "log" "lorem/api" "lorem/image" @@ -12,6 +8,11 @@ import ( "net/http" "os" "path" + + "github.com/gorilla/handlers" + "github.com/gorilla/mux" + "github.com/spf13/pflag" + "github.com/spf13/viper" ) func init() { @@ -20,7 +21,11 @@ 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( + "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") @@ -49,15 +54,16 @@ func main() { 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"), + 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) + r.HandleFunc("/image/{category}/{id}", a.SizeHandler).Methods(http.MethodGet) r.HandleFunc("/image", a.SizeHandler).Methods(http.MethodGet) r.PathPrefix("/").HandlerFunc(a.NotFound)