Moved parameters to standalone fle
This commit is contained in:
20
main.go
20
main.go
@@ -6,20 +6,28 @@ import (
|
||||
"fmt"
|
||||
"hackernewsletter/db"
|
||||
"hackernewsletter/hackernews"
|
||||
"hackernewsletter/params"
|
||||
"log"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/config"
|
||||
"github.com/aws/aws-sdk-go-v2/service/dynamodb"
|
||||
)
|
||||
|
||||
func main() {
|
||||
conf, err := params.LoadConfig(".")
|
||||
if err != nil {
|
||||
log.Fatal("Cannot load config:", err)
|
||||
}
|
||||
|
||||
table := flag.String("t", "", "The name of the table")
|
||||
flag.Parse()
|
||||
|
||||
if *table == "" {
|
||||
fmt.Println("You must specify a table name (-t TABLE)")
|
||||
fmt.Println("Table name not specified. Using default name.")
|
||||
table = &conf.TableName
|
||||
}
|
||||
|
||||
cfg, err := config.LoadDefaultConfig(context.TODO(), config.WithRegion("eu-central-1"))
|
||||
cfg, err := config.LoadDefaultConfig(context.TODO(), config.WithRegion(conf.AwsRegion))
|
||||
if err != nil {
|
||||
panic("Unable to load SDK config, " + err.Error())
|
||||
}
|
||||
@@ -43,16 +51,16 @@ func main() {
|
||||
resp, err = db.GetTableInfo(context.TODO(), client, input)
|
||||
}
|
||||
|
||||
fmt.Printf("Table %v has %v elements", *table, resp.Table.ItemCount)
|
||||
fmt.Printf("Table %v has %v elements\n", *table, resp.Table.ItemCount)
|
||||
|
||||
newsIds := hackernews.GetTopNewsIds()
|
||||
newsIds := hackernews.GetTopNewsIds(conf.TopNews)
|
||||
|
||||
var newsBatch []db.News
|
||||
|
||||
for i := 0; i < 10; i++ {
|
||||
myNews := hackernews.GetNewsById(newsIds[i])
|
||||
myNews := hackernews.GetNewsById(newsIds[i], conf.SingleNews)
|
||||
newsBatch = append(newsBatch, myNews)
|
||||
}
|
||||
|
||||
db.AddNewsBatch(newTable, newsBatch)
|
||||
db.AddNewsBatch(newTable, newsBatch, conf.BatchSize)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user