-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
61 lines (46 loc) · 1.18 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
51
52
53
54
55
56
57
58
59
60
61
package main
import (
"context"
"fmt"
"net/http"
"os"
"video-transcriber/api"
"video-transcriber/infrastructure"
"github.com/rs/cors"
"github.com/rs/zerolog/log"
speechpb "google.golang.org/genproto/googleapis/cloud/speech/v1"
)
type Phrase struct {
SoundexMap map[string]*speechpb.WordInfo
Words []*speechpb.WordInfo
Transcript string
Time float64
Confidence float64
}
type Note struct {
Title string
Results []*Phrase
}
func main() {
server := api.Init()
ctx, shutdownApplication := context.WithCancel(context.Background())
server.HandleShutdownSignals(shutdownApplication)
migrationType := os.Getenv("DB_MIGRATION")
if migrationType != "" {
err := infrastructure.CreateTables(server.Db)
if err != nil {
log.Fatal().Err(err).Msg("Could not run migrations")
}
}
port := os.Getenv("SERVER_PORT")
if port == "" {
port = "80"
}
httpServer := &http.Server{Addr: fmt.Sprintf(":%s", port), Handler: cors.AllowAll().Handler(server)}
serverDone := make(chan error)
go func() {
serverDone <- httpServer.ListenAndServe()
}()
log.Info().Msg("Server is ready for requests!")
server.AwaitForShutdown(ctx, httpServer, serverDone, shutdownApplication)
}