-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
60 lines (50 loc) · 3.19 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
package main
import (
"fmt"
"github.com/couchbase-examples/golang-quickstart/controllers"
_ "github.com/couchbase-examples/golang-quickstart/controllers"
"github.com/couchbase-examples/golang-quickstart/db"
_ "github.com/couchbase-examples/golang-quickstart/docs"
"github.com/couchbase-examples/golang-quickstart/routes"
services "github.com/couchbase-examples/golang-quickstart/service"
"github.com/gin-gonic/gin"
)
// @title Golang Quickstart using Gin Gonic
// @version 1.0
// @description
// @description This API provides operations for multiple collections in the database, including CRUD operations and query examples.
// @description We have a visual representation of the API documentation using Swagger, which allows you to interact with the API's endpoints directly through the browser. It provides a clear view of the API, including endpoints, HTTP methods, request parameters, and response objects.
// @description Click on an individual endpoint to expand it and see detailed information. This includes the endpoint's description, possible response status codes, and the request parameters it accepts.
// @description Trying Out the API
// @description You can try out an API by clicking on the "Try it out" button next to the endpoints.
// @description - Parameters: If an endpoint requires parameters, Swagger UI provides input boxes for you to fill in. This could include path parameters, query strings, headers, or the body of a POST/PUT request.
// @description - Execution: Once you've inputted all the necessary parameters, you can click the "Execute" button to make a live API call. Swagger UI will send the request to the API and display the response directly in the documentation. This includes the response code, response headers, and response body.
// @description Models
// @description <div style="float: left;">Swagger documents the structure of request and response bodies using models. These models define the expected data structure using JSON schema and are extremely helpful in understanding what data to send and expect.
// @description For details on the API, please check the tutorial on the Couchbase Developer Portal: https://developer.couchbase.com/tutorial-quickstart-golang-gin-gonic
// @query.collection.format multi
func main() {
router := gin.Default()
// Initialize the cluster
cluster := db.InitializeCluster()
// Initialize the scope
scope := db.GetScope(cluster)
// Create service instances
airlineService := services.NewAirlineService(scope)
airportService := services.NewAirportService(scope)
routeService := services.NewRouteService(scope)
// Create controller instances
airlineController := controllers.NewAirlineController(airlineService)
airportController := controllers.NewAirportController(airportService)
routeController := controllers.NewRouteController(routeService)
// Pass to Controllers struct to hold controller instances
controllers := routes.Controllers{
AirlineController: airlineController,
AirportController: airportController,
RouteController: routeController,
}
// Setup routes and pass the Controllers struct
routes.SetupCollectionRoutes(router, controllers)
fmt.Println("The application is running on http://127.0.0.1:8080 ")
router.Run(":8080")
}