MCPcopy
hub / github.com/tdewolff/minify / Match

Method Match

minify.go:186–201  ·  view source on GitHub ↗

Match returns the pattern and minifier that gets matched with the mediatype. It returns nil when no matching minifier exists. It has the same matching algorithm as Minify.

(mediatype string)

Source from the content-addressed store, hash-verified

184// It returns nil when no matching minifier exists.
185// It has the same matching algorithm as Minify.
186func (m *M) Match(mediatype string) (string, map[string]string, MinifierFunc) {
187 m.mutex.RLock()
188 defer m.mutex.RUnlock()
189
190 mimetype, params := parse.Mediatype([]byte(mediatype))
191 if minifier, ok := m.literal[string(mimetype)]; ok { // string conversion is optimized away
192 return string(mimetype), params, minifier.Minify
193 }
194
195 for _, minifier := range m.pattern {
196 if minifier.pattern.Match(mimetype) {
197 return minifier.pattern.String(), params, minifier.Minify
198 }
199 }
200 return string(mimetype), params, nil
201}
202
203// Minify minifies the content of a Reader and writes it to a Writer (safe for concurrent use).
204// An error is returned when no such mimetype exists (ErrNotExist) or when an error occurred in the minifier function.

Callers 3

MinifyMimetypeMethod · 0.80
WriteMethod · 0.80
TestMatchFunction · 0.80

Calls 2

stringFunction · 0.50
StringMethod · 0.45

Tested by 1

TestMatchFunction · 0.64