This repository was archived by the owner on Oct 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
79 lines (68 loc) · 1.6 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package main
import (
"context"
"encoding/json"
"fmt"
"github.com/FACorreiaa/Stay-Healthy-Backend/server"
"github.com/joho/godotenv"
_ "github.com/joho/godotenv"
"log"
"net/http"
"os"
)
// @title StayHealthy Swagger Documentation
// @version 2.0
// @description Alpha server built with Go and Chi
// @termsOfService http://swagger.io/terms/
// @contact.name API Support
// @contact.url http://www.swagger.io/support
// @contact.email support@swagger.io
// @license.name Apache 2.0
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html
// @host localhost:8080
// @BasePath /
// @schemes http
func main() {
if err := run(context.Background()); err != nil {
fmt.Println(err)
log.Fatalf("%+v", err)
}
}
func run(ctx context.Context) error {
err := godotenv.Load(".env")
if os.Getenv("APP_ENV") == "dev" {
if err != nil {
fmt.Println(err)
log.Fatal("Error loading .env file")
}
}
s, err := server.NewServer()
//println("err %+v", err)
if err != nil {
s.Close()
fmt.Println(err)
//log.Fatalf("%+v", err)
return err
}
err = s.Run(ctx)
defer s.Close()
return err
}
// HealthCheck godoc
// @Summary Show the status of server.
// @Description get the status of server.
// @Tags root
// @Accept */*
// @Produce json
// @Success 200 {object} map[string]interface{}
// @Router / [get]
func HealthCheck(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
res := map[string]interface{}{
"data": "Server is up and running",
}
err := json.NewEncoder(w).Encode(res)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
}