MCPcopy Create free account
hub / github.com/Unpackerr/unpackerr / openFile

Function openFile

init/config/main.go:145–168  ·  view source on GitHub ↗

openFile opens a file or url for the parser, or returns the internal file.

(fileName string)

Source from the content-addressed store, hash-verified

143
144// openFile opens a file or url for the parser, or returns the internal file.
145func 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
170func createDefinedSection(def *Def, section *Header, sectionName section) *Header {
171 params := make([]*Param, 0, len(section.Params))

Callers 1

mainFunction · 0.85

Calls 1

ErrorfMethod · 0.65

Tested by

no test coverage detected