Created
January 31, 2018 04:40
-
-
Save icholy/ebafad381328c0452fdfad922b4de6c2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"encoding/xml" | |
"fmt" | |
"log" | |
) | |
func main() { | |
msg := &Message{ | |
Header: &Header{ | |
MsgRefID: "The-Long-Id", | |
Version: "0.2.5", | |
}, | |
Body: &Body{ | |
LoginRequest: &LoginRequest{ | |
Name: "ilia", | |
Password: "beer", | |
}, | |
}, | |
} | |
data, err := xml.MarshalIndent(msg, " ", " ") | |
if err != nil { | |
log.Fatal(err) | |
} | |
fmt.Println(string(data)) | |
} | |
// Root MESSAGE | |
type Message struct { | |
XMLName xml.Name `xml:"MSG_IVEF"` | |
Header *Header `xml:"Header"` | |
Body *Body `xml:"Body"` | |
} | |
// HEADER part of every message with version and uniqueness information | |
type Header struct { | |
// Must be an Universally Unique Identifier for each message (TU-T Rec. X.667 | ISO/IEC 9834-8.) | |
// Reply messages refer to this id to identify the message they are replying to. | |
// In its canonical form, a UUID consists of 32 hexadecimal digits, displayed in 5 groups separated by hyphens, | |
// in the form 8-4-4-4-12 for a total of 36 characters, enclosed by brackets. | |
// For example: {550e8400-e29b-41d4-a716-446655440000} | |
MsgRefID string `xml:"MsgRefId,attr"` | |
// Defines the version of the protocol used. Syntax is major.minor.patch patch releases fix only bugs, | |
// minor releases may add functionality but are compatible, major releases are not compatible | |
Version string `xml:"Version,attr"` | |
} | |
type Body struct { | |
LoginRequest *LoginRequest `xml:"LoginRequest,omitempty"` | |
} | |
// DATA login message with details of the user | |
type LoginRequest struct { | |
Encryption int `xml:"Encryption,attr"` // 1 = plain 2 - 6 the 5 most common encryption 0 = custom | |
Name string `xml:"Name,attr"` // Login name | |
Password string `xml:"Password,attr"` // Password value | |
} | |
// DATA login response with acceptance or deny with optional reason | |
type LoginResponse struct { | |
// String describing reason for declining, only used when result is "Declined" | |
Reason string `xml:"Reason,attr,omitempty"` | |
// Corresponds to the original MsgRefId from the Login.xml message. | |
// Must be an Universally Unique Identifier (TU-T Rec. X.667 | ISO/IEC 9834-8.) | |
ResponseOn string `xml:"ResponseOn,attr"` | |
// 1 = Accepted 2 = Declined | |
Result int `xml:"Result,attr"` | |
} | |
// DATA logout message, the server will drop the connection if logout is successfull | |
type Logout struct{} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment