-
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.
Draft for put landing page; identified TODOs
Issue: #25
- Loading branch information
Showing
4 changed files
with
81 additions
and
6 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
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,51 @@ | ||
package cloud | ||
|
||
import ( | ||
"context" | ||
"sync" | ||
|
||
"github.com/aws/aws-sdk-go-v2/aws" | ||
"github.com/aws/aws-sdk-go-v2/service/dynamodb" | ||
"github.com/aws/aws-sdk-go-v2/service/dynamodb/types" | ||
"github.com/rivernews/GoTools" | ||
|
||
"github.com/google/uuid" | ||
) | ||
|
||
var ( | ||
dynamoDBClient *dynamodb.Client | ||
dynamoDBClientOnce sync.Once | ||
) | ||
|
||
func SharedDynamoDBClient() *dynamodb.Client { | ||
dynamoDBClientOnce.Do(func() { | ||
dynamoDBClient = dynamodb.NewFromConfig(ShareAWSConfig()) | ||
}) | ||
return dynamoDBClient | ||
} | ||
|
||
func DynamoDBPutItem(ctx context.Context, item map[string]types.AttributeValue) *dynamodb.PutItemOutput { | ||
tableID := GoTools.GetEnvVarHelper("MEDIA_TABLE_ID") | ||
if tableID == "" { | ||
GoTools.Logger("ERROR", "MEDIA_TABLE_ID is required please set this env var") | ||
} | ||
|
||
if _, exist := item["uuid"]; !exist { | ||
item["uuid"] = uuid.New().String() | ||
} | ||
|
||
if _, exist := item["createdAt"]; !exist { | ||
// TODO | ||
} | ||
|
||
out, err := dynamoDBClient.PutItem(ctx, &dynamodb.PutItemInput{ | ||
TableName: aws.String(tableID), | ||
Item: item, | ||
}) | ||
|
||
if err != nil { | ||
GoTools.Logger("ERROR", err.Error()) | ||
} | ||
|
||
return out | ||
} |