01_update-user-controller

command
v0.0.0-...-42ea4af Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2021 License: MIT Imports: 4 Imported by: 0

README

Install Mongo

Go get driver for mongo

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

In this step

Don't run this code

Just making updates - a several step process.

We will need a mongo session to use in the CRUD methods

We need our UserControllers to have access to a mongo sessions.

Let's add this to controllers/user.go

UserController struct {
    session *mgo.Session
}

And now add this to controllers/user.go

func NewUserController(s *mgo.Session) *UserController {
    return &UserController{s}
}

And now add this to main.go

func getSession() *mgo.Session {
    // Connect to our local mongo
    s, err := mgo.Dial("mongodb://localhost")

    // Check if connection error, is mongo running?
    if err != nil {
        panic(err)
    }
    return s
}

and this

uc := controllers.NewUserController(getSession())
  1. Enter this at the terminal

        curl http://localhost:8080/user/1
    

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