Skip to content

Instantly share code, notes, and snippets.

@moonsub-kim
moonsub-kim / dynamodb_retry.go
Last active March 25, 2022 11:17
dynamodb_retry.go
var timeout time.Time = 30 * time.Millisecond
var maxRetry int = 3
func queryWithRetry(ctx context.Context, input *dynamodb.QueryInput) (*dynamodb.QueryOutput, error) {
for i := 0; i < maxRetry; i++ {
res, err := func() (*dynamodb.QueryOutput, error) {
timeoutCtx, cancel := context.WithTimeout(ctx, timeout)
defer cancel()
return dynamoDB.Query(input)
}()
@moonsub-kim
moonsub-kim / main.go
Last active March 10, 2022 05:33
Refresh sts token in background
package main
const (
envAWSEndpoint = "AWS_ENDPOINT"
envAWSRegion = "AWS_REGION"
)
func main() {
endPoint := os.Getenv(envAWSEndpoint)
region := os.Getenv(envAWSRegion)
@moonsub-kim
moonsub-kim / refresh_provider.go
Created March 3, 2022 13:48
refresh provider
package main
import (
"log"
"sync"
"time"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/session"
@moonsub-kim
moonsub-kim / clienttrace_example.go
Last active February 8, 2024 03:20
http connection pool in go explained
var startTime time.Time
trace := &httptrace.ClientTrace {
TLSHandshakeStart: func() {
startTime = time.Now()
},
TLSHandshakeDone: func(s tls.ConnectionState, err error) {
fmt.Sprintf("%v elapsed", time.Now() - startTime)
},
}
@moonsub-kim
moonsub-kim / main.go
Last active March 7, 2022 15:09
Refresh sts token in background
package main
const (
envAWSEndpoint = "AWS_ENDPOINT"
envAWSRegion = "AWS_REGION"
)
func main() {
endPoint := os.Getenv(envAWSEndpoint)
region := os.Getenv(envAWSRegion)
@moonsub-kim
moonsub-kim / env.go
Created January 6, 2021 08:55
Read env vars using viper
package main
import (
"github.com/mitchellh/mapstructure"
"github.com/spf13/viper"
)
type Config struct {
MysqlHost string `mapstructure:"MYSQL_HOST"`
LogLevel string `mapstructure:"LOG_LEVEL"`
@moonsub-kim
moonsub-kim / refresh_provider.go
Last active January 6, 2021 08:55
refresh credentials profvider
package main
import (
"context"
"sync"
"time"
"github.com/aws/aws-sdk-go/aws/credentials"
)