go.charczuk.com@v0.0.0-20240327042549-bc490516bd1a/projects/nodes/pkg/funcs/fetch_csv.go (about) 1 /* 2 3 Copyright (c) 2024 - Present. Will Charczuk. All rights reserved. 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file at the root of the repository. 5 6 */ 7 8 package funcs 9 10 import ( 11 "context" 12 13 "go.charczuk.com/projects/nodes/pkg/types" 14 ) 15 16 // FetchCSV fetches a CSV from a given url. 17 func FetchCSV(ctx context.Context, url string) (*types.Table, error) { 18 contents, err := fetchURL(ctx, url) 19 if err != nil { 20 return nil, err 21 } 22 defer contents.Close() 23 24 table, err := types.TableFromCSVReader(contents) 25 if err != nil { 26 return nil, err 27 } 28 return table, nil 29 }