-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
62 lines (48 loc) · 1.34 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
package main
import (
"log"
"net/http"
"os"
"github.com/gin-gonic/gin"
"github.com/joho/godotenv"
swaggerFiles "github.com/swaggo/files"
ginSwagger "github.com/swaggo/gin-swagger"
_ "github.com/vinodnextcoder/golang-mongo-server/docs"
"github.com/vinodnextcoder/golang-mongo-server/routes"
)
// @title Swagger Example API
// @version 1.0
// @description This is a sample gin web server
// @contact.name vinod
// @contact.url http://www.swagger.io/support
// @contact.email support@swagger.io
// @host localhost:3001
// @BasePath /
// @externalDocs.description OpenAPI
// @externalDocs.url https://swagger.io/resources/open-api/
func main() {
err := godotenv.Load(".env.dev")
if err != nil {
log.Fatal("Error loading .env file")
}
//run database
// configs.ConnectDB()
port := os.Getenv("PORT")
router := gin.Default()
router.GET("/", helloCall)
routes.UserRoute(router)
router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
router.Run("0.0.0.0:" + port)
}
// helloCall godoc
// @Summary hellow example
// @Schemes
// @Description Hello
// @Tags example
// @Accept json
// @Produce json
// @Success 200 {string} Hello, You created a Web App!
// @Router / [get]
func helloCall(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"message": "Hello, You created a Web App!"})
}