Browse Source
Co-authored-by: andrey1s <andrey@4devs.pro> Reviewed-on: https://gitoa.ru/go-4devs/mime/pulls/1 Co-authored-by: andrey <andrey@4devs.io> Co-committed-by: andrey <andrey@4devs.io>pull/2/head
andrey
2 years ago
16 changed files with 25739 additions and 10119 deletions
@ -0,0 +1,42 @@ |
|||
kind: pipeline |
|||
name: default |
|||
|
|||
steps: |
|||
- name: golangci-lint |
|||
image: golangci/golangci-lint:v1.49 |
|||
volumes: |
|||
- name: deps |
|||
path: /go/src/mod |
|||
commands: |
|||
- golangci-lint run --timeout 5m |
|||
|
|||
- name: test |
|||
image: golang |
|||
volumes: |
|||
- name: deps |
|||
path: /go/src/mod |
|||
commands: |
|||
- go test ./... |
|||
|
|||
- name: scripts golangci-lint |
|||
image: golangci/golangci-lint:v1.49 |
|||
volumes: |
|||
- name: deps |
|||
path: /go/src/mod |
|||
commands: |
|||
- cd scripts |
|||
- golangci-lint run --timeout 5m |
|||
|
|||
- name: scripts test |
|||
image: golang |
|||
volumes: |
|||
- name: deps |
|||
path: /go/src/mod |
|||
commands: |
|||
- cd scripts |
|||
- go test ./... |
|||
|
|||
volumes: |
|||
- name: deps |
|||
temp: {} |
|||
|
@ -0,0 +1,43 @@ |
|||
linters-settings: |
|||
dupl: |
|||
threshold: 100 |
|||
funlen: |
|||
lines: 100 |
|||
statements: 50 |
|||
goconst: |
|||
min-len: 2 |
|||
min-occurrences: 2 |
|||
gocyclo: |
|||
min-complexity: 15 |
|||
golint: |
|||
min-confidence: 0 |
|||
govet: |
|||
check-shadowing: true |
|||
lll: |
|||
line-length: 140 |
|||
maligned: |
|||
suggest-new: true |
|||
misspell: |
|||
locale: US |
|||
varnamelen: |
|||
min-name-length: 2 |
|||
|
|||
linters: |
|||
enable-all: true |
|||
disable: |
|||
- varcheck |
|||
- maligned |
|||
- scopelint |
|||
- nosnakecase |
|||
- ifshort |
|||
- golint |
|||
- interfacer |
|||
- structcheck |
|||
- deadcode |
|||
- exhaustivestruct |
|||
- exhaustruct |
|||
|
|||
# is disabled because of generics. You can track the evolution of the generics support by following the https://github.com/golangci/golangci-lint/issues/2649 |
|||
- rowserrcheck |
|||
- sqlclosecheck |
|||
- wastedassign |
@ -1,2 +1,3 @@ |
|||
# mime |
|||
|
|||
[![Build Status](https://drone.gitoa.ru/api/badges/go-4devs/mime/status.svg)](https://drone.gitoa.ru/go-4devs/mime) |
|||
|
File diff suppressed because it is too large
File diff suppressed because it is too large
File diff suppressed because it is too large
File diff suppressed because it is too large
@ -0,0 +1,36 @@ |
|||
package mime_test |
|||
|
|||
import ( |
|||
"fmt" |
|||
|
|||
"gitoa.ru/go-4devs/mime" |
|||
) |
|||
|
|||
func ExampleMime_String() { |
|||
fmt.Printf("%v", mime.TextHTML) |
|||
|
|||
// Output:
|
|||
// text/html
|
|||
} |
|||
|
|||
func ExampleMime_Is() { |
|||
fmt.Printf("%v\n%v", |
|||
mime.TextHTML.Is(mime.ApplicationJSON, mime.ApplicationJavascript), |
|||
mime.TextHTML.Is(mime.ApplicationJavascript, mime.TextHTML), |
|||
) |
|||
|
|||
// Output:
|
|||
// false
|
|||
// true
|
|||
} |
|||
|
|||
func ExampleMime_ExtTypes() { |
|||
fmt.Printf("%v\n%v", |
|||
mime.TextHTML.ExtTypes(), |
|||
mime.ApplicationJavascript.ExtTypes(), |
|||
) |
|||
|
|||
// Output:
|
|||
// [html htm shtml]
|
|||
// [js mjs jsm]
|
|||
} |
@ -1,19 +1,58 @@ |
|||
// Code generated by gitoa.ru/go-4devs/mime and sourse {{.Source}} |
|||
package {{.ExtPackage}} |
|||
|
|||
import "fmt" |
|||
|
|||
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) String() string { |
|||
switch v { |
|||
{{- 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 ( |
|||
{{- range $key, $value := .Extensions }} |
|||
{{ name $.ExtPrefix $key }} = "{{ $key }}" |
|||
{{- range $value := .Extensions }} |
|||
{{ name $.ExtPrefix $value.Name }} Ext = {{ $value.ID }} |
|||
{{- end}} |
|||
) |
|||
|
|||
func Mime(name string) []string { |
|||
func ExtFromString(name string) Ext { |
|||
switch name { |
|||
{{- range $key, $value := .Extensions }} |
|||
case {{ name $.ExtPrefix $key }}: |
|||
return {{ value $value }} |
|||
{{- range $value := .Extensions }} |
|||
case "{{- $value.Name -}}": |
|||
return {{ name $.ExtPrefix $value.Name }} |
|||
{{- end}} |
|||
} |
|||
|
|||
return nil |
|||
|
|||
return 0 |
|||
} |
|||
|
|||
|
@ -1,19 +1,57 @@ |
|||
// Code generated by gitoa.ru/go-4devs/mime and sourse {{.Source}} |
|||
package {{.MimePackage}} |
|||
|
|||
import "fmt" |
|||
|
|||
type Mime int |
|||
|
|||
type MimeTypes []Mime |
|||
|
|||
func (v Mime) Is(types ...Mime) bool { |
|||
for _, mime := range types { |
|||
if mime == v { |
|||
return true |
|||
} |
|||
} |
|||
|
|||
return false |
|||
} |
|||
|
|||
func (v Mime) String() string { |
|||
switch v { |
|||
{{- range $value := .Mimes }} |
|||
case {{ name $.MimePrefix $value.Name }}: |
|||
return "{{- $value.Name -}}" |
|||
{{- end}} |
|||
} |
|||
|
|||
return fmt.Sprintf("Mime(%d)",v) |
|||
} |
|||
|
|||
func (v Mime) ExtTypes() ExtTypes{ |
|||
switch v { |
|||
{{- range $value := .Mimes }} |
|||
case {{ name $.MimePrefix $value.Name }}: |
|||
return []Ext{ {{- value $.ExtPrefix $value.Value -}} } |
|||
{{- end}} |
|||
} |
|||
|
|||
return nil |
|||
} |
|||
|
|||
const ( |
|||
{{- range $key, $value := .Mimes }} |
|||
{{ name $.MimePrefix $key }} = "{{ $key }}" |
|||
{{- range $value := .Mimes }} |
|||
{{ name $.MimePrefix $value.Name }} Mime = {{ $value.ID }} |
|||
{{- end}} |
|||
) |
|||
|
|||
func Extension(name string) []string { |
|||
func MimeFromString(name string) Mime { |
|||
switch name { |
|||
{{- range $key, $value := .Mimes }} |
|||
case {{ name $.MimePrefix $key }}: |
|||
return {{ value $value }} |
|||
{{- range $value := .Mimes }} |
|||
case "{{- $value.Name -}}": |
|||
return {{ name $.MimePrefix $value.Name }} |
|||
{{- end}} |
|||
} |
|||
|
|||
return nil |
|||
|
|||
return 0 |
|||
} |
|||
|
Loading…
Reference in new issue