Skip to content

IvanovIurii/TestGo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

  1. install packages: Mux router, Mongo, Toml
  • go get -u -v github.com/gorilla/mux
  • go get -u -v gopkg.in/mgo.v2
  • go get -u -v github.com/BurntSushi/toml
  1. install mongoDB

  2. put DB configuration to config.toml, if you have other DB port, e.g. server="127.0.0.1:27017" database="posts"

  3. run mongoDB:

  • for Windows, so "C:\Program Files\MongoDB\Server\4.0\bin\mongod.exe"
  1. run main.go
  1. CURL for testing
  • GET /login - to get TOKEN, which then you have to use to authenticate in HEADER

  • POST /posts - to create a post, for example: curl -H "Token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdXRob3JpemVkIjp0cnVlLCJleHAiOjE1NDMzNjEyNDcsInVzZXIiOiJpdXJpaSJ9.dxZ3FISCEfIPpoYuE9tBvFrTKAJ7beElCIWGxB_lvKU" -d '{"title":"test", "content":"test"}' -H "Content-Type: application/json" -X POST http://localhost:8080/posts

where "Token" was generated by "/login",

{"title":"test", "content":"test", "created":"timestamp"} is payload

where "Token" was generated by "/login"

From scrach DB is empty, it is droped every run of main.go (see init() in rest.go)

NOTE: to test in your ENV it should be extracted here $GOPATH/src/github.com/ The whole path will be like that: $GOPATH/src/github.com/<name_of_the_working_directory>

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages