Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New utron feature #5

Open
gernest opened this issue Dec 11, 2015 · 2 comments
Open

New utron feature #5

gernest opened this issue Dec 11, 2015 · 2 comments

Comments

@gernest
Copy link

gernest commented Dec 11, 2015

@OsvaldoTCF @euller88 I have added a helper method for rendering JSON responses in *utron.BaseController.

Now Instead of this

func (a *EmailSupplierAction) Post() {
    a.Ctx.Request().ParseForm()
    dec := json.NewDecoder(a.Ctx.Request().Body)

    var m map[string]interface{}
    dec.Decode(&m)

    eml := new(models.EmailSupplier)
    eml.Email, _ = m["email"].(string)

    i, _ := strconv.Atoi(m["supplier"].(string))
    eml.SupplierID = uint(i)

    a.Ctx.DB.Create(&eml)

    rtn, _ := json.Marshal(eml)

    a.Ctx.Set(http.StatusCreated)
    a.Ctx.Write(rtn)
    fmt.Println(string(rtn[:]))
}

You can Just do this

func (a *EmailSupplierAction) Post() {
    a.Ctx.Request().ParseForm()
    dec := json.NewDecoder(a.Ctx.Request().Body)

    var m map[string]interface{}
    dec.Decode(&m)

    eml := new(models.EmailSupplier)
    eml.Email, _ = m["email"].(string)

    i, _ := strconv.Atoi(m["supplier"].(string))
    eml.SupplierID = uint(i)

    a.Ctx.DB.Create(&eml)

    a.RenderJSON(eml, http.StatusCreated)

    fmt.Println(string(rtn[:]))
}

You will need to update utron by

go get -v -u github.com/gernest/utron
@eullerpereira94
Copy link
Contributor

@gernest Really nice! This is a very helpful feature that you've added, we are already using it! It's a really good thing that you are so interested is our little project. So we ask you the following: when you feel that o2go is worthy, can you please add him as one of the examples of utron? This is our initial intention, and we will be very pleased if that happens. By the way, there's some things about utron that should be interesting of adding, so I'll open an issue about it.

@gernest
Copy link
Author

gernest commented Dec 11, 2015

@euller88 sure. I will add this, just keep up the good work. I'm sure you will learn alot about golang in general and I will help you to move in the right direction.

Okay, feel free to open Issues

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants