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)
| 184 | // It returns nil when no matching minifier exists. |
| 185 | // It has the same matching algorithm as Minify. |
| 186 | func (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. |