You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
80 lines
1.4 KiB
80 lines
1.4 KiB
// Code generated by gitoa.ru/go-4devs/mime and sourse {{.Source}}
|
|
package {{.ExtPackage}}
|
|
|
|
import (
|
|
"encoding"
|
|
"fmt"
|
|
)
|
|
|
|
var (
|
|
_ encoding.TextUnmarshaler = (*Mime)(nil)
|
|
_ encoding.TextMarshaler = (*Mime)(nil)
|
|
)
|
|
|
|
type Ext int
|
|
|
|
type ExtTypes []Ext
|
|
|
|
func (v Ext) Is(types ...Ext) bool {
|
|
for _, ext := range types {
|
|
if ext == v {
|
|
return true
|
|
}
|
|
}
|
|
|
|
return false
|
|
}
|
|
|
|
func (v Ext) MarshalText() ([]byte, error) {
|
|
return []byte(v.String()), nil
|
|
}
|
|
|
|
func (s *Ext) UnmarshalText(text []byte) error {
|
|
ext := ExtFromString(string(text))
|
|
*s = ext
|
|
|
|
return nil
|
|
}
|
|
|
|
func (v Ext) String() string {
|
|
switch v {
|
|
case {{ name .ExtPrefix "unrecognized" }}:
|
|
return "unrecognized"
|
|
{{- range $value := .Extensions }}
|
|
case {{ name $.ExtPrefix $value.Name }}:
|
|
return "{{- $value.Name -}}"
|
|
{{- end}}
|
|
}
|
|
|
|
return fmt.Sprintf("Ext(%d)",v)
|
|
}
|
|
|
|
func (v Ext) MimeTypes() MimeTypes{
|
|
switch v {
|
|
{{- range $value := .Extensions }}
|
|
case {{ name $.ExtPrefix $value.Name }}:
|
|
return MimeTypes{ {{- value $.MimePrefix $value.Value -}} }
|
|
{{- end}}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
const (
|
|
{{ name .ExtPrefix "unrecognized" }} Ext = 0
|
|
{{- range $value := .Extensions }}
|
|
{{ name $.ExtPrefix $value.Name }} Ext = {{ $value.ID }}
|
|
{{- end}}
|
|
)
|
|
|
|
func ExtFromString(name string) Ext {
|
|
switch name {
|
|
{{- range $value := .Extensions }}
|
|
case "{{- $value.Name -}}":
|
|
return {{ name $.ExtPrefix $value.Name }}
|
|
{{- end}}
|
|
}
|
|
|
|
return {{ name .ExtPrefix "unrecognized" }}
|
|
}
|
|
|
|
|