-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
66 lines (53 loc) · 1.77 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
package main
import (
"context"
"kaps/routes"
"kaps/types"
_ "kaps/docs"
"github.com/gin-gonic/gin"
swaggerFiles "github.com/swaggo/files"
ginSwagger "github.com/swaggo/gin-swagger"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
)
const uri = "mongodb://192.168.15.47:27017"
// @title KAPS API document
// @version 1.0
// @description This is a sample server celler server.
// @termsOfService http://swagger.io/terms/
// @contact.name API Support
// @contact.url http://www.swagger.io/support
// @contact.email [email protected]
// @license.name Apache 2.0
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html
// @host 192.168.15.248:3000
// @BasePath /
// @securityDefinitions.basic BasicAuth
// @externalDocs.description OpenAPI
// @externalDocs.url https://swagger.io/resources/open-api/
func main() {
// Initialize the MongoDB variable
MongoDB := &types.MongoDB{}
// Use the SetServerAPIOptions() method to set the Stable API version to 1
serverAPI := options.ServerAPI(options.ServerAPIVersion1)
opts := options.Client().ApplyURI(uri).SetServerAPIOptions(serverAPI)
// Create a new client and connect to the server
client, err := mongo.Connect(context.TODO(), opts)
if err != nil {
panic(err)
}
// Assign the client to the MongoDB.Client field
MongoDB.Client = client
defer func() {
if err = MongoDB.Client.Disconnect(context.TODO()); err != nil {
panic(err)
}
}()
router := gin.Default()
// router.Use(static.Serve("/", static.LocalFile("./cube/dist", false)))
// router.NoRoute(func(c *gin.Context) { c.File("./cube/dist/index.html") })
router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
public := router.Group("/")
routes.PublicRoutes(public, MongoDB)
router.Run("0.0.0.0:3000")
}