Skip to content

axeldeveloper/rest_go_mongo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Projeto rest em golang e mongodb

My Go logo

projeto

  • GOLANG
  • MONGODB
  • REST
  • MVC

Craindo projeto

$ go mod init rest_go_mongo

Install dependencies

$ go get -u github.com/globalsign/mgo
$ go get -u github.com/gorilla/mux

// (A powerful HTTP router and URL matcher for building Go web servers with)

Estrutura do projeto

  • raiz:
    • main.go
    • config/config.go
    • api/app/handler/common.go
    • api/app/handler/employess.go
    • api/app/handler/mgodao.go
    • api/app/model/model.go (vamos mudar para Employes)

Routes - Rotas do Projeto

GET  => http://localhost:8000/employess
POST => http://localhost:8000/employees

GOROOT

A GOROOT é uma variável de ambiente que especifica o local da instalação do go e pode ser definido como C: \ Go

GOPATH

A GOPATH é uma variável de ambiente que especifica o local do seu espaço de trabalho.

Se a GOPATH não estiver definido, presume-se que esteja $HOME/go nos sistemas Unix e %USERPROFILE%\go no Windows.

Crie a variável de ambiente GOPATH e faça referência ao caminho do espaço de trabalho

Demostração do Hello World

$ go version
//go version go1.12 windows/amd64


/* Fenced code */
package main
import "fmt"
func main() {
    fmt.Println("hello world")
}
$ go run hello-world.go
// nome do objeto
$ go build hello-world.go
$ ls
// hello-world    hello-world.go
$ ./hello-world
// hello world

Criando Model

    type Employee struct {
        _id    bson.ObjectId `bson:"_id,omitempty"`
        Name   string        `json:"name"`
        City   string        `json:"city"`
        Age    int           `json:"age"`
        Status bool          `json:"status"`
    }

Rum server

go run main.go

Deployment

Axel Alexander

My web site

Contributing

Versioning

Authors

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the LICENSE.md file for details

About

projeto rest com mongo e go

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages