func validateExt(config Config, ext string) error {
	if !strings.HasPrefix(ext, ".") {
		return fmt.Errorf(`mime: invalid extension "%v" (must start with dot)`, ext)
	}
	if _, ok := config.Extensions[ext]; ok {
		return fmt.Errorf(`mime: duplicate extension "%v" found`, ext)
	}
	return nil
}
validateExt checks for valid file name extension.
package mime
import (
	"fmt"
	"strings"
	"github.com/tmpim/casket"
	"github.com/tmpim/casket/caskethttp/httpserver"
)
func init() {
	casket.RegisterPlugin("mime", casket.Plugin{
		ServerType: "http",
		Action:     setup,
	})
}
func setup(c *casket.Controller) error {
	config, err := mimeParse(c)
	if err != nil {
		return err
	}
	httpserver.GetConfig(c).AddMiddleware(func(next httpserver.Handler) httpserver.Handler {
		return Mime{Next: next, Configs: config}
	})
	return nil
}
func mimeParse(c *casket.Controller) (Config, error) {
	config := Config{
		UseDefaults: false,
		Extensions:  make(map[string]string),
	}
	for c.Next() {
		args := c.RemainingArgs()
		switch len(args) {
		case 2:
			if err := validateExt(config, args[0]); err != nil {
				return config, err
			}
			config.Extensions[args[0]] = args[1]
		case 1:
			if args[0] == "ext_defaults" {
				config.UseDefaults = true
				break
			}
			return config, c.ArgErr()
		case 0:
			for c.NextBlock() {
				ext := c.Val()
				if ext == "ext_defaults" {
					config.UseDefaults = true
					continue
				}
				if err := validateExt(config, ext); err != nil {
					return config, err
				}
				if !c.NextArg() {
					return config, c.ArgErr()
				}
				config.Extensions[ext] = c.Val()
			}
		}
	}
	return config, nil
}