https://github.com/jmbl1685/golang-restapi
Minimal server with Golang using gorilla/mux + MongoDB
https://github.com/jmbl1685/golang-restapi
golang gorilla-mux mongobd rest-api
Last synced: 4 months ago
JSON representation
Minimal server with Golang using gorilla/mux + MongoDB
- Host: GitHub
- URL: https://github.com/jmbl1685/golang-restapi
- Owner: jmbl1685
- Created: 2018-06-06T21:35:23.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2018-06-08T17:56:42.000Z (about 7 years ago)
- Last Synced: 2025-01-04T14:42:04.538Z (5 months ago)
- Topics: golang, gorilla-mux, mongobd, rest-api
- Language: Go
- Homepage:
- Size: 2.28 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
Awesome Lists containing this project
README
# API REST Example using Go [Golang]
Used modules
```
go get github.com/gorilla/mux
go get github.com/rs/cors
go get gopkg.in/mgo.v2
go get gopkg.in/mgo.v2/bson
go get github.com/jasonsoft/go-short-id
```## CRUD Football player
Player Model:
```go
type Player struct {
Id string `json:"id"`
Name string `json:"name"`
Team string `json:"team"`
Position string `json:"position"`
Dorsal int `json:"dorsal"`
Nationality string `json:"nationality"`
ImageUrl string `json:"image"`
}
```
Player Controllers:```go
func AddPlayer(w http.ResponseWriter, r *http.Request){...}
func GetPlayer(w http.ResponseWriter, r *http.Request){...}
func GetPlayerById(w http.ResponseWriter, r *http.Request){...}
func DeletePlayer(w http.ResponseWriter, r *http.Request){...}
func UpdatePlayer(w http.ResponseWriter, r *http.Request){...}
```
Player Routes:
```go
router = mux.NewRouter()router.HandleFunc("/player", controllers.AddPlayer).Methods("POST")
router.HandleFunc("/player", controllers.GetPlayer).Methods("GET")
router.HandleFunc("/player/{id}", controllers.GetPlayerById).Methods("GET")
router.HandleFunc("/player/{id}", controllers.DeletePlayer).Methods("DELETE")
router.HandleFunc("/player/{id}", controllers.UpdatePlayer).Methods("PUT")
```