aboutsummaryrefslogtreecommitdiffhomepage
path: root/modules/caddyhttp/fileserver/staticfiles.go
diff options
context:
space:
mode:
Diffstat (limited to 'modules/caddyhttp/fileserver/staticfiles.go')
-rw-r--r--modules/caddyhttp/fileserver/staticfiles.go26
1 files changed, 26 insertions, 0 deletions
diff --git a/modules/caddyhttp/fileserver/staticfiles.go b/modules/caddyhttp/fileserver/staticfiles.go
index 3d7032804..48812cfec 100644
--- a/modules/caddyhttp/fileserver/staticfiles.go
+++ b/modules/caddyhttp/fileserver/staticfiles.go
@@ -153,6 +153,16 @@ type FileServer struct {
// a 404 error. By default, this is false (disabled).
PassThru bool `json:"pass_thru,omitempty"`
+ // Override the default sort.
+ // It includes the following options:
+ // - sort_by: name(default), namedirfirst, size, time
+ // - order: asc(default), desc
+ // eg.:
+ // - `sort time desc` will sort by time in descending order
+ // - `sort size` will sort by size in ascending order
+ // The first option must be `sort_by` and the second option must be `order` (if exists).
+ SortOptions []string `json:"sort,omitempty"`
+
// Selection of encoders to use to check for precompressed files.
PrecompressedRaw caddy.ModuleMap `json:"precompressed,omitempty" caddy:"namespace=http.precompressed"`
@@ -236,6 +246,22 @@ func (fsrv *FileServer) Provision(ctx caddy.Context) error {
fsrv.precompressors[ae] = p
}
+ // check sort options
+ for idx, sortOption := range fsrv.SortOptions {
+ switch idx {
+ case 0:
+ if sortOption != sortByName && sortOption != sortByNameDirFirst && sortOption != sortBySize && sortOption != sortByTime {
+ return fmt.Errorf("the first option must be one of the following: %s, %s, %s, %s, but got %s", sortByName, sortByNameDirFirst, sortBySize, sortByTime, sortOption)
+ }
+ case 1:
+ if sortOption != sortOrderAsc && sortOption != sortOrderDesc {
+ return fmt.Errorf("the second option must be one of the following: %s, %s, but got %s", sortOrderAsc, sortOrderDesc, sortOption)
+ }
+ default:
+ return fmt.Errorf("only max 2 sort options are allowed, but got %d", idx+1)
+ }
+ }
+
return nil
}