FAQ
Hi

Im trying convert a classical class that i implement in my PHP projects
called WebResponse:


*This is my current struct code:*

type WebResponse struct {
Success bool `json:"success"`
Message string `json:"message"`
Data map[string]interface{} `json:"data"`
}

func (s *WebResponse) AddData(key string, value interface{}) {
if s.Data == nil {
s.Data = make(map[string]interface{})
}

s.Data[key] = value
}

func (s *WebResponse) ClearData() {
s.Data = make(map[string]interface{})
}

func (s *WebResponse) AddDataError(key string, message string) {
if s.Data == nil {
s.Data = make(map[string]interface{})
}

// s.Data.Errors = ????

//newError := make(map[string]interface{})
//newError[key] = message
//s.Data["errors"] = append(s.Data["errors"], newError)
}


*How to use:*

var response WebResponse
response.Success = true
response.Message = "auth-fail"
response.AddData("username", "invalid username")
response.ClearData()
response.AddData("password", "invalid password")
response.AddDataError("password", "too short")

*The problem:*

The method AddDataError need store a key inside "data" with an array of
errors.

*The expected result:*

{

    - success: true,
    - message: "auth-fail",
    - Data:
    {
    - password: "invalid password"
       - },
       - errors:
       {
          - password: "too short"
          }
       }

}

--
Atenciosamente,
Paulo Coutinho.
Blog: blog.prsolucoes.com
Site: www.prsolucoes.com
Msn: paulo@prsolucoes.com
Skype: paulo.prsolucoes
Telefone: +55 21 9386-0010
Consultor Certificado Bindows

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Paulo Coutinho at Jul 18, 2015 at 5:52 am
    *The expected result:*

    {

        - success: true,
        - message: "auth-fail",
        - data:
        {
        - password: "invalid password",
           - action: "show-profile-update",
           errors:
           {
              - password: "too short"
              }
           }

    }

    How i can make my struct accept it?




    On Saturday, July 18, 2015 at 2:50:44 AM UTC-3, Paulo Coutinho wrote:

    Hi

    Im trying convert a classical class that i implement in my PHP projects
    called WebResponse:


    *This is my current struct code:*

    type WebResponse struct {
    Success bool `json:"success"`
    Message string `json:"message"`
    Data map[string]interface{} `json:"data"`
    }

    func (s *WebResponse) AddData(key string, value interface{}) {
    if s.Data == nil {
    s.Data = make(map[string]interface{})
    }

    s.Data[key] = value
    }

    func (s *WebResponse) ClearData() {
    s.Data = make(map[string]interface{})
    }

    func (s *WebResponse) AddDataError(key string, message string) {
    if s.Data == nil {
    s.Data = make(map[string]interface{})
    }

    // s.Data.Errors = ????

    //newError := make(map[string]interface{})
    //newError[key] = message
    //s.Data["errors"] = append(s.Data["errors"], newError)
    }


    *How to use:*

    var response WebResponse
    response.Success = true
    response.Message = "auth-fail"
    response.AddData("username", "invalid username")
    response.ClearData()
    response.AddData("password", "invalid password")
    response.AddDataError("password", "too short")

    *The problem:*

    The method AddDataError need store a key inside "data" with an array of
    errors.

    *The expected result:*

    {

    - success: true,
    - message: "auth-fail",
    - Data:
    {
    - password: "invalid password"
    - },
    - errors:
    {
    - password: "too short"
    }
    }

    }

    --
    Atenciosamente,
    Paulo Coutinho.
    Blog: blog.prsolucoes.com
    Site: www.prsolucoes.com
    Msn: paulo@prsolucoes.com
    Skype: paulo.prsolucoes
    Telefone: +55 21 9386-0010
    Consultor Certificado Bindows
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Egon at Jul 18, 2015 at 8:10 am
    https://play.golang.org/p/c8JHsS5mvC
    On Saturday, 18 July 2015 08:52:47 UTC+3, Paulo Coutinho wrote:

    *The expected result:*

    {

    - success: true,
    - message: "auth-fail",
    - data:
    {
    - password: "invalid password",
    - action: "show-profile-update",
    errors:
    {
    - password: "too short"
    }
    }

    }

    How i can make my struct accept it?




    On Saturday, July 18, 2015 at 2:50:44 AM UTC-3, Paulo Coutinho wrote:

    Hi

    Im trying convert a classical class that i implement in my PHP projects
    called WebResponse:


    *This is my current struct code:*

    type WebResponse struct {
    Success bool `json:"success"`
    Message string `json:"message"`
    Data map[string]interface{} `json:"data"`
    }

    func (s *WebResponse) AddData(key string, value interface{}) {
    if s.Data == nil {
    s.Data = make(map[string]interface{})
    }

    s.Data[key] = value
    }

    func (s *WebResponse) ClearData() {
    s.Data = make(map[string]interface{})
    }

    func (s *WebResponse) AddDataError(key string, message string) {
    if s.Data == nil {
    s.Data = make(map[string]interface{})
    }

    // s.Data.Errors = ????

    //newError := make(map[string]interface{})
    //newError[key] = message
    //s.Data["errors"] = append(s.Data["errors"], newError)
    }


    *How to use:*

    var response WebResponse
    response.Success = true
    response.Message = "auth-fail"
    response.AddData("username", "invalid username")
    response.ClearData()
    response.AddData("password", "invalid password")
    response.AddDataError("password", "too short")

    *The problem:*

    The method AddDataError need store a key inside "data" with an array of
    errors.

    *The expected result:*

    {

    - success: true,
    - message: "auth-fail",
    - Data:
    {
    - password: "invalid password"
    - },
    - errors:
    {
    - password: "too short"
    }
    }

    }

    --
    Atenciosamente,
    Paulo Coutinho.
    Blog: blog.prsolucoes.com
    Site: www.prsolucoes.com
    Msn: pa...@prsolucoes.com <javascript:>
    Skype: paulo.prsolucoes
    Telefone: +55 21 9386-0010
    Consultor Certificado Bindows
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Gautam Dey at Jul 18, 2015 at 5:02 pm
    I was considering recommending something like this as well. I did not,
    because I did not know what his data section could contain.

    Gautam.
    On Sat, Jul 18, 2015 at 1:10 AM, Egon wrote:

    https://play.golang.org/p/c8JHsS5mvC

    On Saturday, 18 July 2015 08:52:47 UTC+3, Paulo Coutinho wrote:

    *The expected result:*

    {

    - success: true,
    - message: "auth-fail",
    - data:
    {
    - password: "invalid password",
    - action: "show-profile-update",
    errors:
    {
    - password: "too short"
    }
    }

    }

    How i can make my struct accept it?




    On Saturday, July 18, 2015 at 2:50:44 AM UTC-3, Paulo Coutinho wrote:

    Hi

    Im trying convert a classical class that i implement in my PHP projects
    called WebResponse:


    *This is my current struct code:*

    type WebResponse struct {
    Success bool `json:"success"`
    Message string `json:"message"`
    Data map[string]interface{} `json:"data"`
    }

    func (s *WebResponse) AddData(key string, value interface{}) {
    if s.Data == nil {
    s.Data = make(map[string]interface{})
    }

    s.Data[key] = value
    }

    func (s *WebResponse) ClearData() {
    s.Data = make(map[string]interface{})
    }

    func (s *WebResponse) AddDataError(key string, message string) {
    if s.Data == nil {
    s.Data = make(map[string]interface{})
    }

    // s.Data.Errors = ????

    //newError := make(map[string]interface{})
    //newError[key] = message
    //s.Data["errors"] = append(s.Data["errors"], newError)
    }


    *How to use:*

    var response WebResponse
    response.Success = true
    response.Message = "auth-fail"
    response.AddData("username", "invalid username")
    response.ClearData()
    response.AddData("password", "invalid password")
    response.AddDataError("password", "too short")

    *The problem:*

    The method AddDataError need store a key inside "data" with an array of
    errors.

    *The expected result:*

    {

    - success: true,
    - message: "auth-fail",
    - Data:
    {
    - password: "invalid password"
    - },
    - errors:
    {
    - password: "too short"
    }
    }

    }

    --
    Atenciosamente,
    Paulo Coutinho.
    Blog: blog.prsolucoes.com
    Site: www.prsolucoes.com
    Msn: pa...@prsolucoes.com
    Skype: paulo.prsolucoes
    Telefone: +55 21 9386-0010
    Consultor Certificado Bindows
    --
    You received this message because you are subscribed to the Google Groups
    "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Gautam Dey at Jul 18, 2015 at 5:03 pm
    Paulo,

    Here is a playground (http://play.golang.org/p/0HiGum2O_n) with a working
    example of how you would do it.

    <iframe src="http://play.golang.org/p/0HiGum2O_n" frameborder="0"
    style="width: 100%; height: 100%"><a href="
    see" rel="nofollow">http://play.golang.org/p/0HiGum2O_n">see this code in play.golang.org
    </a></iframe>

    Hope that helps,

    Gautam.




    On Fri, Jul 17, 2015 at 10:52 PM, Paulo Coutinho wrote:

    *The expected result:*

    {

    - success: true,
    - message: "auth-fail",
    - data:
    {
    - password: "invalid password",
    - action: "show-profile-update",
    errors:
    {
    - password: "too short"
    }
    }

    }

    How i can make my struct accept it?




    On Saturday, July 18, 2015 at 2:50:44 AM UTC-3, Paulo Coutinho wrote:

    Hi

    Im trying convert a classical class that i implement in my PHP projects
    called WebResponse:


    *This is my current struct code:*

    type WebResponse struct {
    Success bool `json:"success"`
    Message string `json:"message"`
    Data map[string]interface{} `json:"data"`
    }

    func (s *WebResponse) AddData(key string, value interface{}) {
    if s.Data == nil {
    s.Data = make(map[string]interface{})
    }

    s.Data[key] = value
    }

    func (s *WebResponse) ClearData() {
    s.Data = make(map[string]interface{})
    }

    func (s *WebResponse) AddDataError(key string, message string) {
    if s.Data == nil {
    s.Data = make(map[string]interface{})
    }

    // s.Data.Errors = ????

    //newError := make(map[string]interface{})
    //newError[key] = message
    //s.Data["errors"] = append(s.Data["errors"], newError)
    }


    *How to use:*

    var response WebResponse
    response.Success = true
    response.Message = "auth-fail"
    response.AddData("username", "invalid username")
    response.ClearData()
    response.AddData("password", "invalid password")
    response.AddDataError("password", "too short")

    *The problem:*

    The method AddDataError need store a key inside "data" with an array of
    errors.

    *The expected result:*

    {

    - success: true,
    - message: "auth-fail",
    - Data:
    {
    - password: "invalid password"
    - },
    - errors:
    {
    - password: "too short"
    }
    }

    }

    --
    Atenciosamente,
    Paulo Coutinho.
    Blog: blog.prsolucoes.com
    Site: www.prsolucoes.com
    Msn: paulo@prsolucoes.com
    Skype: paulo.prsolucoes
    Telefone: +55 21 9386-0010
    Consultor Certificado Bindows
    --
    You received this message because you are subscribed to the Google Groups
    "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Paulo Coutinho at Jul 18, 2015 at 3:32 pm
    Wow man. Very nice help. Thanks too much.
    On Sat, Jul 18, 2015 at 3:57 AM, Gautam Dey wrote:

    Paulo,

    Here is a playground (http://play.golang.org/p/0HiGum2O_n) with a working
    example of how you would do it.

    <iframe src="http://play.golang.org/p/0HiGum2O_n" frameborder="0"
    style="width: 100%; height: 100%"><a href="
    see" rel="nofollow">http://play.golang.org/p/0HiGum2O_n">see this code in play.golang.org
    </a></iframe>

    Hope that helps,

    Gautam.




    On Fri, Jul 17, 2015 at 10:52 PM, Paulo Coutinho wrote:

    *The expected result:*

    {

    - success: true,
    - message: "auth-fail",
    - data:
    {
    - password: "invalid password",
    - action: "show-profile-update",
    errors:
    {
    - password: "too short"
    }
    }

    }

    How i can make my struct accept it?




    On Saturday, July 18, 2015 at 2:50:44 AM UTC-3, Paulo Coutinho wrote:

    Hi

    Im trying convert a classical class that i implement in my PHP projects
    called WebResponse:


    *This is my current struct code:*

    type WebResponse struct {
    Success bool `json:"success"`
    Message string `json:"message"`
    Data map[string]interface{} `json:"data"`
    }

    func (s *WebResponse) AddData(key string, value interface{}) {
    if s.Data == nil {
    s.Data = make(map[string]interface{})
    }

    s.Data[key] = value
    }

    func (s *WebResponse) ClearData() {
    s.Data = make(map[string]interface{})
    }

    func (s *WebResponse) AddDataError(key string, message string) {
    if s.Data == nil {
    s.Data = make(map[string]interface{})
    }

    // s.Data.Errors = ????

    //newError := make(map[string]interface{})
    //newError[key] = message
    //s.Data["errors"] = append(s.Data["errors"], newError)
    }


    *How to use:*

    var response WebResponse
    response.Success = true
    response.Message = "auth-fail"
    response.AddData("username", "invalid username")
    response.ClearData()
    response.AddData("password", "invalid password")
    response.AddDataError("password", "too short")

    *The problem:*

    The method AddDataError need store a key inside "data" with an array of
    errors.

    *The expected result:*

    {

    - success: true,
    - message: "auth-fail",
    - Data:
    {
    - password: "invalid password"
    - },
    - errors:
    {
    - password: "too short"
    }
    }

    }

    --
    Atenciosamente,
    Paulo Coutinho.
    Blog: blog.prsolucoes.com
    Site: www.prsolucoes.com
    Msn: paulo@prsolucoes.com
    Skype: paulo.prsolucoes
    Telefone: +55 21 9386-0010
    Consultor Certificado Bindows
    --
    You received this message because you are subscribed to the Google Groups
    "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.

    --
    Atenciosamente,
    Paulo Coutinho.
    Blog: blog.prsolucoes.com
    Site: www.prsolucoes.com
    Msn: paulo@prsolucoes.com
    Skype: paulo.prsolucoes
    Telefone: +55 21 9386-0010
    Consultor Certificado Bindows

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedJul 18, '15 at 5:50a
activeJul 18, '15 at 5:03p
posts6
users3
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase