Moved parameters to standalone fle

This commit is contained in:
Riccardo
2022-07-15 16:18:06 +02:00
parent 61f2fff12f
commit 54b2dda79a
8 changed files with 547 additions and 13 deletions

20
main.go
View File

@@ -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)
}