07_mgo_controllers

command
v0.0.0-...-baf0b24 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 18, 2020 License: MIT Imports: 5 Imported by: 0

README

Update the Controllers to Interface with MongoDB

Updating the Model for Accepting Mongo style data

Note the Change in the ID field which now became of the type bson.ObjectId

Also the additional descriptions for bson data used by MongoDB.

Install MongoDB

https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/

https://docs.mongodb.com/manual/tutorial/install-mongodb-on-windows/

Install the Driver

go get -u gopkg.in/mgo.v2
go get -u gopkg.in/mgo.v2/bson

Modify the Code the Add Mongo DB Connection

Curl for sending data

curl http://localhost:8080/user/2501

API : http://localhost:8080/user/:id

POST Data

curl -X POST -H "Content-Type: application/json" -d '{"name":"Harish","gender":"male","age":32}' http://localhost:8080/user

where:

  • -X is short for --request = type of request Specifies the custom request method to use in communicating with server
  • -H is short for --header = Adding Header field
  • -d is short for --data = String data

Delete User

curl -X DELETE -H "Content-Type: application/json" http://localhost:8080/user/3

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL