-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
50 lines (45 loc) · 1.42 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package main
import (
"context"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/service/dynamodb"
"github.com/dbuduev/authz-service-go/dygraph"
resource "github.com/dbuduev/authz-service-go/http"
"github.com/dbuduev/authz-service-go/repository"
"log"
"net/http"
"time"
)
func GetClient() *dynamodb.Client {
// Create DynamoDB client
cfg, err := config.LoadDefaultConfig(context.TODO(),
config.WithSharedConfigFiles(config.DefaultSharedConfigFiles),
config.WithSharedCredentialsFiles(config.DefaultSharedCredentialsFiles),
)
if err != nil {
log.Fatalf("failed to load configuration, %v", err)
}
return dynamodb.NewFromConfig(cfg, func(o *dynamodb.Options) {
//o.ClientLogMode |= aws.LogRequestWithBody
o.EndpointResolver = dynamodb.EndpointResolverFunc(
func(region string, options dynamodb.EndpointResolverOptions) (aws.Endpoint, error) {
options.DisableHTTPS = true
return aws.Endpoint{URL: "http://localhost:8000", HostnameImmutable: true}, nil
})
})
}
func main() {
repo := repository.CreateRepository(dygraph.CreateGraphClient(GetClient(), "test"))
server := http.Server{
Addr: ":8080",
ReadTimeout: 30 * time.Second,
WriteTimeout: 90 * time.Second,
IdleTimeout: 120 * time.Second,
Handler: resource.ConfigureHandler(repo),
}
err := server.ListenAndServe()
if err != nil && err != http.ErrServerClosed {
panic(err)
}
}