@@ -5,20 +5,20 @@ import (
5
5
"log"
6
6
"net/http"
7
7
"os"
8
+
8
9
// "context"
9
- // "time"
10
- "go.mongodb.org/mongo-driver/bson"
11
- "github.com/vinodnextcoder/golang-mongo-server/mongoconnect"
12
- // "go.mongodb.org/mongo-driver/mongo"
13
- // "go.mongodb.org/mongo-driver/mongo/options"
14
- // "go.mongodb.org/mongo-driver/mongo/readpref"
15
-
16
- "github.com/joho/godotenv"
10
+ // "time"
11
+ "github.com/vinodnextcoder/golang-mongo-server/mongoconnect"
12
+
13
+ // "go.mongodb.org/mongo-driver/mongo"
14
+ // "go.mongodb.org/mongo-driver/mongo/options"
15
+ // "go.mongodb.org/mongo-driver/mongo/readpref"
16
+
17
17
"github.com/gin-gonic/gin"
18
+ "github.com/joho/godotenv"
18
19
swaggerFiles "github.com/swaggo/files"
19
20
ginSwagger "github.com/swaggo/gin-swagger"
20
21
_ "github.com/vinodnextcoder/golang-mongo-server/docs"
21
-
22
22
)
23
23
24
24
// @title Swagger Example API
@@ -37,70 +37,65 @@ import (
37
37
func main () {
38
38
39
39
err := godotenv .Load (".env.dev" )
40
-
41
- if err != nil {
42
- log .Fatal ("Error loading .env file" )
43
- }
44
-
45
- // Get Client, Context, CancelFunc and
46
- // err from connect method.
47
- client , ctx , cancel , err := mongoconnect .Connect ("mongodb://localhost:27017/test" )
48
- if err != nil {
49
- panic (err )
50
- }
51
-
52
- // Release resource when the main
53
- // function is returned.
54
- defer mongoconnect .Close (client , ctx , cancel )
55
-
56
- // Ping mongoDB with Ping method
57
- mongoconnect .Ping (client , ctx )
58
-
59
-
60
- // Create a object of type interface to store
61
- // the bson values, that we are inserting into database.
62
- var document interface {}
63
-
64
-
65
- document = bson.D {
66
- {"rollNo" , 175 },
67
- {"maths" , 80 },
68
- {"science" , 90 },
69
- {"computer" , 95 },
70
- }
71
-
72
- dbname := os .Getenv ("DBNAME" )
73
- // insertOne accepts client , context, database
74
- // name collection name and an interface that
75
- // will be inserted into the collection.
76
- // insertOne returns an error and a result of
77
- // insert in a single document into the collection.
78
- insertOneResult , err := mongoconnect .Insertdata (client , ctx , dbname , "marks" , document )
79
-
80
- // handle the error
81
- if err != nil {
82
- panic (err )
83
- }
84
-
85
- // print the insertion id of the document,
86
- // if it is inserted.
87
- fmt .Println ("Result of InsertOne" )
88
- fmt .Println (insertOneResult .InsertedID )
89
-
90
- port := os .Getenv ("PORT" )
40
+
41
+ if err != nil {
42
+ log .Fatal ("Error loading .env file" )
43
+ }
44
+
45
+ // Get Client, Context, CancelFunc and
46
+ // err from connect method.
47
+ client , ctx , cancel , err := mongoconnect .Connect ("mongodb://localhost:27017/test" )
48
+ if err != nil {
49
+ panic (err )
50
+ }
51
+
52
+ // Release resource when the main
53
+ // function is returned.
54
+ // defer mongoconnect.Close(client, ctx, cancel)
55
+
56
+ // // Ping mongoDB with Ping method
57
+ // // mongoconnect.Ping(client, ctx)
58
+
59
+ // // Create a object of type interface to store
60
+ // // the bson values, that we are inserting into database.
61
+ // var document interface{}
62
+
63
+ // document = bson.D{
64
+ // {"rollNo", 175},
65
+ // {"maths", 80},
66
+ // {"science", 90},
67
+ // {"computer", 95},
68
+ // }
69
+
70
+ // dbname := os.Getenv("DBNAME")
71
+ // // insertOne accepts client , context, database
72
+ // // name collection name and an interface that
73
+ // // will be inserted into the collection.
74
+ // // insertOne returns an error and a result of
75
+ // // insert in a single document into the collection.
76
+ // insertOneResult, err := mongoconnect.Insertdata(client, ctx, dbname, "marks", document)
77
+
78
+ // handle the error
79
+ if err != nil {
80
+ panic (err )
81
+ }
82
+
83
+ // print the insertion id of the document,
84
+ // if it is inserted.
85
+ fmt .Println ("Result of InsertOne" , client , ctx , cancel )
86
+ // fmt.Println(insertOneResult.InsertedID)
87
+
88
+ port := os .Getenv ("PORT" )
91
89
92
90
router := gin .Default ()
93
91
94
92
router .GET ("/" , helloCall )
95
- router .POST ("/add" , mongoconnect .PostMarks )
93
+ router .POST ("/add" , mongoconnect .PostMarks )
96
94
router .GET ("/swagger/*any" , ginSwagger .WrapHandler (swaggerFiles .Handler ))
97
95
98
-
99
- router .Run ("0.0.0.0:" + port )
96
+ router .Run ("0.0.0.0:" + port )
100
97
}
101
98
102
-
103
-
104
99
// helloCall godoc
105
100
// @Summary hellow example
106
101
// @Schemes
0 commit comments