Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing minor item on csv parser #2

Merged
merged 3 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion functions/src/init/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ module github.com/tarmac-project/example-airport-lookup-go/functions/src/init

go 1.21

require github.com/tarmac-project/tarmac/pkg/sdk v0.5.0
require (
github.com/tarmac-project/example-airport-lookup-go v0.0.0-20231023001804-82de5425cb1e
github.com/tarmac-project/tarmac/pkg/sdk v0.5.0
)

require (
github.com/enescakir/emoji v1.0.0 // indirect
github.com/valyala/fastjson v1.6.4 // indirect
github.com/wapc/wapc-guest-tinygo v0.3.3 // indirect
)
4 changes: 4 additions & 0 deletions functions/src/init/go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
github.com/enescakir/emoji v1.0.0 h1:W+HsNql8swfCQFtioDGDHCHri8nudlK1n5p2rHCJoog=
github.com/enescakir/emoji v1.0.0/go.mod h1:Bt1EKuLnKDTYpLALApstIkAjdDrS/8IAgTkKp+WKFD0=
github.com/pquerna/ffjson v0.0.0-20190930134022-aa0246cd15f7 h1:xoIK0ctDddBMnc74udxJYBqlo9Ylnsp1waqjLsnef20=
github.com/pquerna/ffjson v0.0.0-20190930134022-aa0246cd15f7/go.mod h1:YARuvh7BUWHNhzDq2OM5tzR2RiCcN2D7sapiKyCel/M=
github.com/tarmac-project/example-airport-lookup-go v0.0.0-20231023001804-82de5425cb1e h1:YK8n/1grlaZra2bEDFg3xfatS5lB7Jx3JyqRSYb+TFI=
github.com/tarmac-project/example-airport-lookup-go v0.0.0-20231023001804-82de5425cb1e/go.mod h1:NM0cKjAxO2xObefEpFZGgnu5g8iVBDk/xnjysv3uHeU=
github.com/tarmac-project/tarmac/pkg/sdk v0.5.0 h1:QKsEf6SXTYrJM9/B4cNoM4RS3/rzuViJaiutEcdSRZQ=
github.com/tarmac-project/tarmac/pkg/sdk v0.5.0/go.mod h1:UTKYV0QFdkJDgV2sJcnuCujVy49MCd8bgi2JmwviJ6E=
github.com/valyala/fastjson v1.6.4 h1:uAUNq9Z6ymTgGhcm0UynUAB6tlbakBrz6CQFax3BXVQ=
Expand Down
18 changes: 16 additions & 2 deletions functions/src/init/main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package main

import (
"bytes"
"fmt"
"github.com/tarmac-project/example-airport-lookup-go/pkg/airport/parsers/csv"
"github.com/tarmac-project/tarmac/pkg/sdk"
)

Expand All @@ -13,13 +15,25 @@ func (f *Function) Handler(_ []byte) ([]byte, error) {
f.tarmac.Logger.Info("Airport raw data download starting")

// Fetch the airport data
_, err := f.tarmac.Function.Call("fetch", []byte(""))
data, err := f.tarmac.Function.Call("fetch", []byte(""))
if err != nil {
f.tarmac.Logger.Error(fmt.Sprintf("Failed to fetch airport data", err))
f.tarmac.Logger.Error(fmt.Sprintf("Failed to fetch airport data - %s", err))
return []byte(""), fmt.Errorf("Failed to fetch airport data: %s", err)
}

// Parse the data
parser, err := csv.New(bytes.NewReader(data))
if err != nil {
f.tarmac.Logger.Error(fmt.Sprintf("Failed to create CSV parser - %s", err))
return []byte(""), fmt.Errorf("Failed to create CSV parser: %s", err)
}

airports, err := parser.Parse()
if err != nil {
f.tarmac.Logger.Error(fmt.Sprintf("Failed to parse airport data - %s", err))
return []byte(""), fmt.Errorf("Failed to parse airport data: %s", err)
}
f.tarmac.Logger.Info(fmt.Sprintf("Fetched %d airports", len(airports)))

// Update the database

Expand Down
10 changes: 9 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,12 @@ module github.com/tarmac-project/example-airport-lookup-go

go 1.21

require github.com/enescakir/emoji v1.0.0
require (
github.com/enescakir/emoji v1.0.0
github.com/tarmac-project/tarmac/pkg/sdk v0.5.0
)

require (
github.com/valyala/fastjson v1.6.4 // indirect
github.com/wapc/wapc-guest-tinygo v0.3.3 // indirect
)
8 changes: 8 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
github.com/enescakir/emoji v1.0.0 h1:W+HsNql8swfCQFtioDGDHCHri8nudlK1n5p2rHCJoog=
github.com/enescakir/emoji v1.0.0/go.mod h1:Bt1EKuLnKDTYpLALApstIkAjdDrS/8IAgTkKp+WKFD0=
github.com/pquerna/ffjson v0.0.0-20190930134022-aa0246cd15f7 h1:xoIK0ctDddBMnc74udxJYBqlo9Ylnsp1waqjLsnef20=
github.com/pquerna/ffjson v0.0.0-20190930134022-aa0246cd15f7/go.mod h1:YARuvh7BUWHNhzDq2OM5tzR2RiCcN2D7sapiKyCel/M=
github.com/tarmac-project/tarmac/pkg/sdk v0.5.0 h1:QKsEf6SXTYrJM9/B4cNoM4RS3/rzuViJaiutEcdSRZQ=
github.com/tarmac-project/tarmac/pkg/sdk v0.5.0/go.mod h1:UTKYV0QFdkJDgV2sJcnuCujVy49MCd8bgi2JmwviJ6E=
github.com/valyala/fastjson v1.6.4 h1:uAUNq9Z6ymTgGhcm0UynUAB6tlbakBrz6CQFax3BXVQ=
github.com/valyala/fastjson v1.6.4/go.mod h1:CLCAqky6SMuOcxStkYQvblddUtoRxhYMGLrsQns1aXY=
github.com/wapc/wapc-guest-tinygo v0.3.3 h1:jLebiwjVSHLGnS+BRabQ6+XOV7oihVWAc05Hf1SbeR0=
github.com/wapc/wapc-guest-tinygo v0.3.3/go.mod h1:mzM3CnsdSYktfPkaBdZ8v88ZlfUDEy5Jh5XBOV3fYcw=
7 changes: 2 additions & 5 deletions pkg/airport/parsers/csv/csv.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,8 @@ func (p *Parser) Parse() ([]airport.Airport, error) {
// Convert the record to an Airport
a, err := RecordToAirport(rec)
if err != nil {
// Skip headers and records with not enough fields
if err == ErrIsHeader || err == ErrNotEnoughFields {
continue
}
return nil, fmt.Errorf("unable to convert record to airport - %w", err)
// Skip any record level errors
continue
madflojo marked this conversation as resolved.
Show resolved Hide resolved
}
// Append the Airport to the slice
airports = append(airports, a)
Expand Down