This is a creation in Article, where the information may have evolved or changed.
the usage of encoding in//golang PackageMainImport("bytes""Encoding/binary""Encoding/hex""Encoding/xml""FMT""OS")funcGoxml () {typeAddressstruct{City, State string}//xml ELEMENT nodes add attributes, need to re-customize struct typeElementwithattrstruct{Attrone string' xml: ' attrone,attr ' Attrtwo string' xml: ' attrtow,attr ' }typePersonstruct{xmlname XML. Name' xml: ' person ' ' Id int' xml: ' id,attr ' Sex string' xml: ' sex,attr ' FirstName string' xml: ' Name>first ' LastName string' xml: ' Name>last ' Age int' xml: ' age ' Height float32' xml: ' Height,omitempty ' EWA elementwithattr' xml:elementwithattr ' //When a child node or attribute is written here (usually not a single string), the "" must be used for encapsulation, otherwise it will not be recognized when reflected Ewachild string' xml: ' Elementwithattr>ewachild ' married bool Address Comment string' xml: ', comment "' } V: = &person{id: -, FirstName:"John", LastName:"Doe", Age: the, Sex:"Female"} v.comment ="need more details." V.address = address{"Hanga Roa","Easter Island"} V.ewa = elementwithattr{"Attribteone","Attributetwo"} V.ewachild ="Elementwithattrchildnode" ENC: = XML. Newencoder (OS. Stdout) Enc. Indent (" "," ")ifERR: = Enc. Encode (v); Err! = Nil {fmt. Printf ("Error:%v\n", err)}}funcMain () {pi: =3.1415926 BUF: = bytes. buffer{}//Using a small encoding, low address corresponding to low byte Binary. Write (&buf, Binary. Littleendian, &PI)//constant floating-point number is float64 by default Fmt. Printf ("buf=% #v \ n", buf. Bytes ())varRPI float64 Binary. Read (&buf, Binary. Littleendian, &rpi) fmt. Printf ("rpi=% #v \ n", RPI)//As with Python's binascii library, conversions between 16 and ASCII characters SRC: ="Go is good language! we are all the same" //Allocate cache space based on encoded length DST: = Make ([]byte, Hex. Encodedlen (len (src))) hex. Encode (DST, []byte (SRC)) fmt. Printf ("dst=%v\n", DST) fmt. Printf ("DST (hex) =%s\n", string (DST))//Allocate cache space based on decoding length Dst2: = Make ([]byte, Hex. Decodedlen (Len (DST))) hex. Decode (Dst2, DST) fmt. Printf ("dst2=%v\n", Dst2) fmt. Printf ("Dst2. (string) =%s\n ", String (DST2)) Goxml ()}