newSource creates a source using the content provider function.
(location string, compress bool, loadContent func() ([]byte, error))
| 46 | |
| 47 | // newSource creates a source using the content provider function. |
| 48 | func newSource(location string, compress bool, loadContent func() ([]byte, error)) (Source, error) { |
| 49 | // strip query part from location if any |
| 50 | locPath := util.SubstringBefore(location, "?") |
| 51 | if locPath == "" { |
| 52 | locPath = location |
| 53 | } |
| 54 | src := Source{ |
| 55 | Name: filepath.Base(locPath), |
| 56 | Origin: location, |
| 57 | Location: location, |
| 58 | Compress: compress, |
| 59 | } |
| 60 | |
| 61 | content, err := loadContent() |
| 62 | if err != nil { |
| 63 | return Source{}, err |
| 64 | } |
| 65 | if err := src.setContent(content); err != nil { |
| 66 | return Source{}, err |
| 67 | } |
| 68 | |
| 69 | return src, nil |
| 70 | } |
| 71 | |
| 72 | func (s *Source) setContent(content []byte) error { |
| 73 | if s.Compress { |
no test coverage detected