-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
executable file
·49 lines (39 loc) · 1.05 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 (
"embed"
"fmt"
"log"
"net/http"
"os"
"os/signal"
"strconv"
"syscall"
"github.com/google/uuid"
"github.com/mwiater/golangconsuldiscovery/config"
"github.com/mwiater/golangconsuldiscovery/consul"
"github.com/mwiater/golangconsuldiscovery/hello"
)
var myUUID = uuid.New()
//go:embed .env
var envVarsFile embed.FS
func main() {
config.EnvVarsFile = envVarsFile
_, err := config.AppConfig()
if err != nil {
log.Fatal("Error: config.AppConfig()")
}
signalChannel := make(chan os.Signal, 1)
signal.Notify(signalChannel, syscall.SIGINT, syscall.SIGTERM)
go func() {
<-signalChannel
fmt.Println("\nShutting down.")
os.Exit(0)
}()
consul.ServiceRegistryWithConsul(config.IPAddress, config.ServerPort, myUUID)
fmt.Printf("Starting Hello Server: %v:%v", config.IPAddress, config.ServerPort)
http.HandleFunc("/hello/api/v1", func(w http.ResponseWriter, r *http.Request) {
hello.HelloHandler(w, r, myUUID)
})
http.HandleFunc("/health", hello.HealthHandler)
http.ListenAndServe(":"+strconv.Itoa(config.ServerPort), nil)
}