-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
494 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
//go:build lambda | ||
|
||
package main | ||
|
||
import ( | ||
"cmp" | ||
"context" | ||
"errors" | ||
"github.com/aws/aws-sdk-go-v2/config" | ||
"github.com/aws/aws-sdk-go-v2/service/s3" | ||
"github.com/explore-flights/monorepo/go/api/search" | ||
"os" | ||
"strconv" | ||
) | ||
|
||
func echoPort() int { | ||
port, _ = strconv.Atoi(os.Getenv("AWS_LWA_PORT")) | ||
return cmp.Or(port, 8080) | ||
} | ||
|
||
func flightRepo(ctx context.Context) (*search.FlightRepo, error) { | ||
dataBucket := os.Getenv("FLIGHTS_DATA_BUCKET") | ||
if dataBucket == "" { | ||
return nil, errors.New("env variable FLIGHTS_DATA_BUCKET required") | ||
} | ||
|
||
cfg, err := config.LoadDefaultConfig(ctx) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return search.NewFlightRepo(s3.NewFromConfig(cfg), dataBucket), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
//go:build !lambda | ||
|
||
package main | ||
|
||
import ( | ||
"context" | ||
"github.com/explore-flights/monorepo/go/api/local" | ||
"github.com/explore-flights/monorepo/go/api/search" | ||
"os" | ||
"path/filepath" | ||
) | ||
|
||
func echoPort() int { | ||
return 8080 | ||
} | ||
|
||
func flightRepo(ctx context.Context) (*search.FlightRepo, error) { | ||
home, err := os.UserHomeDir() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return search.NewFlightRepo( | ||
local.NewS3Client(filepath.Join(home, "Downloads", "local_s3")), | ||
"flights_data_bucket", | ||
), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
//go:build !lambda | ||
|
||
package local | ||
|
||
import ( | ||
"context" | ||
"github.com/aws/aws-sdk-go-v2/service/s3" | ||
"os" | ||
"path/filepath" | ||
) | ||
|
||
type S3Client struct { | ||
basePath string | ||
} | ||
|
||
func NewS3Client(basePath string) *S3Client { | ||
return &S3Client{basePath} | ||
} | ||
|
||
func (s3c *S3Client) GetObject(ctx context.Context, params *s3.GetObjectInput, optFns ...func(*s3.Options)) (*s3.GetObjectOutput, error) { | ||
f, err := os.Open(filepath.Join(s3c.basePath, *params.Bucket, *params.Key)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &s3.GetObjectOutput{Body: f}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.