This is a restful service, built with golang.
These services include create an article, get article details based on passed key and get articles details based on passed tags and date parameter
-
I have created a swagger documentation for articles API
- open this link in the browser: https://editor.swagger.io/
- copy article.yaml file and paste in the open editor
Package | Justification |
---|---|
go-chi/chi |
Router & Middleware |
logrus |
Log wrapper |
Dependancies
- go get gopkg.in/mgo.v2
- go get github.com/go-chi/ch
- go github.com/sirupsen/logrus
- Please install monogodb first, here is docs link : https://docs.mongodb.com/manual/tutorial/install-mongodb-enterprise-on-os-x/
- Install Golang. Two options,
brew
, or from their websitebrew install golang
- golang.org
- Go workspace setup - slightly different workspace than most. See the Golang site for more details.
- Create the proper directories if you don't already have them
mkdir -p $GOPATH/src/github.com/ mkdir -p $GOPATH/src && mkdir -p $GOPATH/bin && mkdir -p $GOPATH/pkg cd $GOPATH/src/github.com/
- Clone repo into the directory you
cd
'd into - Build the binary
cd article go get go build
go get
go build
go run main.go
curl -X POST \
http://localhost:8001/articles \
-H 'Cache-Control: no-cache' \
-H 'Content-Type: application/json' \
-H 'id: 1' \
-d '{
"id": "1",
"title":"latest science shows that potato chips are better for you than sugar",
"Date": "2016-09-22",
"Body": "some text, potentially containing simple markup about how potato chips are great",
"Tags":["health", "fitness", "science"]
}'
201 Created
curl -X GET \
http://localhost:8001/articles/1 \
-H 'Cache-Control: no-cache'
{
"id": "1",
"title": "latest science shows that potato chips are better for you than sugar",
"date": "2016-09-22",
"body": "some text, potentially containing simple markup about how potato chips are great",
"tags": [
"health",
"fitness",
"science"
]
}
curl -X GET \
http://localhost:8001/tags/health/20160922 \
-H 'Cache-Control: no-cache'
{
"tag": "health",
"count": 1,
"articles": [
"1"
],
"related_tags": [
"fitness",
"science"
]
}
- Now in current test cases, records getting created in database I need to mock it.
- Add Benchmarking test for all endpoints