-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
49 lines (41 loc) · 1.04 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
package main
import (
"log"
"net/http"
"github.com/AnnuCode/devops-practice/utils"
)
var (
dynamodbClient = utils.CreateLocalClient()
tableName = "Movies"
tableBasics = utils.TableBasics{TableName: tableName,
DynamoDbClient: dynamodbClient}
)
func main() {
exists, err := tableBasics.TableExists()
if err != nil {
panic(err)
}
if !exists {
log.Printf("Creating table %v...\n", tableName)
_, err = tableBasics.CreateMovieTable()
if err != nil {
panic(err)
} else {
log.Printf("Created table %v.\n", tableName)
}
written, _ := tableBasics.AddMovieBatch(utils.Movies, 3)
log.Printf("%d movies were added to the database", written)
} else {
log.Printf("Table %v already exists with movies.\n", tableName)
}
movie, err := tableBasics.GetMovie("First movie", 2001)
if err == nil {
log.Println(movie)
}
mux := http.NewServeMux()
mux.HandleFunc("/health", healthHandler)
mux.HandleFunc("/secret", secretHandler)
log.Println("Starting server on :5000")
err = http.ListenAndServe(":5000", mux)
log.Fatal(err)
}