FAQ
Want to customise encoding/xml marshal.go file for my project
- https://github.com/golang/go/tree/master/src/encoding

But don't know how to compile, build / or if I have to fork

Tried to find solution on google but haven't found any related topic

Can you please help

Thanks very much in advance,

Rgds,

Abhi

--
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

  • Michael Banzon at Feb 24, 2016 at 11:35 am
    Why do you need to customise?

    There might be a way to solve the problem you are having using only
    Go/client code - without modifying the standard libraries.

    On a side note: If you don't know how to proceed with the chaning of the
    standard library I'd probably advise against for now.
    On Wed, Feb 24, 2016 at 12:06 PM wrote:

    Want to customise encoding/xml marshal.go file for my project -
    https://github.com/golang/go/tree/master/src/encoding

    But don't know how to compile, build / or if I have to fork

    Tried to find solution on google but haven't found any related topic

    Can you please help

    Thanks very much in advance,

    Rgds,

    Abhi

    --
    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.
  • Desaiabhijit at Feb 24, 2016 at 11:49 am
    Thanks for the reply

    My requirement is - to expose the Structure or Variables - depends on who
    is invoking the xml service

    so example

    type MyStruct Structure {

    A string <-- want to expose when client type X invoking the service
    B string <-- want to expose when client type Y invoking the service

    }

    2 solutions here

    1. To use omit node using xml tag and make that node "nil" depends on which
    client is invoking the service
    2. Change in encoding/xml package itself to customise for my requirement

    2nd would help to simply apply appropriate tag to variable eg `xml:"MaskAB"`

    Please let me know the correct way

    Thanks,

    Abhi

    On Wednesday, February 24, 2016 at 5:05:32 PM UTC+5:30, mbanzon wrote:

    Why do you need to customise?

    There might be a way to solve the problem you are having using only
    Go/client code - without modifying the standard libraries.

    On a side note: If you don't know how to proceed with the chaning of the
    standard library I'd probably advise against for now.

    On Wed, Feb 24, 2016 at 12:06 PM <desaia...@gmail.com <javascript:>>
    wrote:
    Want to customise encoding/xml marshal.go file for my project -
    https://github.com/golang/go/tree/master/src/encoding

    But don't know how to compile, build / or if I have to fork

    Tried to find solution on google but haven't found any related topic

    Can you please help

    Thanks very much in advance,

    Rgds,

    Abhi

    --
    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...@googlegroups.com <javascript:>.
    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.
  • Egon at Feb 24, 2016 at 12:23 pm

    On Wednesday, 24 February 2016 13:49:27 UTC+2, desaia...@gmail.com wrote:
    Thanks for the reply

    My requirement is - to expose the Structure or Variables - depends on who
    is invoking the xml service

    so example

    type MyStruct Structure {

    A string <-- want to expose when client type X invoking the service
    B string <-- want to expose when client type Y invoking the service

    }
    Use two different structures.?

    Also possible:

    Implement a filter, i.e. reads xml and writes out only allowed tags),
    should be pretty trivial using xml.Encoder and xml.Decoder.

    Use "omitempty" and leave appropriate field empty (and clear appropriate
    fields).


    *Probably more solutions depending what you are actually doing and how it
    fits together with all other systems.*

    + Egon

    2 solutions here

    1. To use omit node using xml tag and make that node "nil" depends on
    which client is invoking the service
    2. Change in encoding/xml package itself to customise for my requirement

    2nd would help to simply apply appropriate tag to variable eg
    `xml:"MaskAB"`

    Please let me know the correct way

    Thanks,

    Abhi

    On Wednesday, February 24, 2016 at 5:05:32 PM UTC+5:30, mbanzon wrote:

    Why do you need to customise?

    There might be a way to solve the problem you are having using only
    Go/client code - without modifying the standard libraries.

    On a side note: If you don't know how to proceed with the chaning of the
    standard library I'd probably advise against for now.
    On Wed, Feb 24, 2016 at 12:06 PM wrote:

    Want to customise encoding/xml marshal.go file for my project -
    https://github.com/golang/go/tree/master/src/encoding

    But don't know how to compile, build / or if I have to fork

    Tried to find solution on google but haven't found any related topic

    Can you please help

    Thanks very much in advance,

    Rgds,

    Abhi

    --
    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...@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.
  • Konstantin Khomoutov at Feb 24, 2016 at 12:29 pm

    On Wed, 24 Feb 2016 03:49:13 -0800 (PST) desaiabhijit@gmail.com wrote:

    Thanks for the reply

    My requirement is - to expose the Structure or Variables - depends on
    who is invoking the xml service

    so example

    type MyStruct Structure {

    A string <-- want to expose when client type X invoking the service
    B string <-- want to expose when client type Y invoking the service

    }

    2 solutions here

    1. To use omit node using xml tag and make that node "nil" depends on
    which client is invoking the service
    2. Change in encoding/xml package itself to customise for my
    requirement

    2nd would help to simply apply appropriate tag to variable eg
    `xml:"MaskAB"`
    I think you're attemting to heavily "over-engeneer" your solution.
    The reason appears to be you fixating on your single type MyStruct
    for no reason: if different kinds of clients need to see different
    kinds of data, why not just use different kinds of data?

    What I'd do is just have three types:

       // Basic, "full" type.
       type myStruct struct {
         A string
         B string
       }

       // Type for clients of type X
       type XStruct struct {
         A string
         // Note that B is missing
       }

       // Type for clients of type Y
       type YStruct struct {
         // Note that A is missing
         B string
       }

    Then in the code processing the request do something along this logic:

       var data myStruct
       populate(&data, someDataSource)

       var value interface{}

       if clientIsOfTypeX() {
         value := XStruct{
           A: data.A,
         }
       } else { // client is of type Y
         value := YStruct{
           B: data.B,
         }
       }

       out, err := enc.Marshal(value)

    Another solution could be to write custom marshaling code which would
    traverse the fields of values of your MyStruct type by
    itself--using the standard reflect packag--and only defer to the
    standard encoding/xml package to marshal the value of each field.
    This way, you can easily skip over a field if it's not to be exposed to
    the particular kind of client and still not modify any standard package.

    It's possible to just copy the code which performs such traversal into
    your own program and then tweak it.

    --
    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.
  • Ojucie at Feb 25, 2016 at 10:27 am

    Abhi wrote:
    ... customise encoding/xml marshal.go file for my project.
    ... to expose the Structure or Variables - depends on who is invoking the
    xml service

    Ops! My internal alarms triggered twice in a row.
    Don't take that route, Abhi. You would be planting headaches.
    Please consider the alternative approaches kindly suggested by our friends
    in this list.



    --
    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.
  • Matt Harden at Feb 26, 2016 at 5:05 am
    Here's one more idea. You can create "wrapper" structs like this:

    https://play.golang.org/p/7pMuaIvS32

    When you embed the original struct, the xml package treats it as if the
    fields in the embedded struct are fields at the top level. Then I override
    the A and B fields in the outer structs and use `xml:",omitempty"` so I can
    make them disappear completely from the output XML. Note that using
    `xml:"-"` won't work because the package ignores that field and then the
    underlying field from the embedded struct is used.

    On Thu, Feb 25, 2016 at 2:28 AM wrote:

    Abhi wrote:
    ... customise encoding/xml marshal.go file for my project.
    ... to expose the Structure or Variables - depends on who is invoking the
    xml service

    Ops! My internal alarms triggered twice in a row.
    Don't take that route, Abhi. You would be planting headaches.
    Please consider the alternative approaches kindly suggested by our friends
    in this list.



    --
    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.
  • Konstantin Khomoutov at Feb 24, 2016 at 11:38 am

    On Wed, 24 Feb 2016 03:06:28 -0800 (PST) desaiabhijit@gmail.com wrote:

    Want to customise encoding/xml marshal.go file for my project
    - https://github.com/golang/go/tree/master/src/encoding

    But don't know how to compile, build / or if I have to fork
    You don't have to mess with Go to do that: just extract the code of the
    single package, encoding/xml, and customize it after renaming.

    Using the `git subtree` tool you can even extract the project's code
    with the full (synthetic) history of its changes.

    People routinely do this when, for instance, they need a feature
    in a package from the standard library which was added in the
    now-unstable version of Go. One example is [1]. If/after the
    missing feature is available in the standard release, the application
    code could be switched back to using the standard library by changing a
    couple of "import" declarations.

    1. https://github.com/rogpeppe/juju-xml

    --
    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
postedFeb 24, '16 at 11:06a
activeFeb 26, '16 at 5:05a
posts8
users6
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase