openFile opens a file or url for the parser, or returns the internal file.
(fileName string)
| 143 | |
| 144 | // openFile opens a file or url for the parser, or returns the internal file. |
| 145 | func openFile(fileName string) (io.ReadCloser, error) { |
| 146 | if fileName == "internal" { |
| 147 | buf := bytes.NewBuffer(confBuilder) |
| 148 | return io.NopCloser(buf), nil |
| 149 | } |
| 150 | |
| 151 | if !strings.HasPrefix(fileName, "http") { |
| 152 | file, err := os.Open(fileName) |
| 153 | if err != nil { |
| 154 | return nil, fmt.Errorf("%s: %w", fileName, err) |
| 155 | } |
| 156 | |
| 157 | return file, nil |
| 158 | } |
| 159 | |
| 160 | http.DefaultClient.Timeout = opTimeout |
| 161 | //nolint:noctx,gosec // because we set a timeout. |
| 162 | resp, err := http.Get(fileName) |
| 163 | if err != nil { |
| 164 | return nil, fmt.Errorf("%s: %w", fileName, err) |
| 165 | } |
| 166 | |
| 167 | return resp.Body, nil |
| 168 | } |
| 169 | |
| 170 | func createDefinedSection(def *Def, section *Header, sectionName section) *Header { |
| 171 | params := make([]*Param, 0, len(section.Params)) |