actually marshal XML data
This commit is contained in:
@@ -0,0 +1,19 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
type MultiStatus struct {
|
||||||
|
Responses []Response `xml:"response"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Response struct {
|
||||||
|
Href string `xml:"href"`
|
||||||
|
PropStat []PropStat `xml:"propstat"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type PropStat struct {
|
||||||
|
Prop Prop `xml:"prop"`
|
||||||
|
Status string `xml:"status"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Prop struct {
|
||||||
|
DisplayName string `xml:"displayname"`
|
||||||
|
}
|
||||||
+11
-4
@@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/xml"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
@@ -9,7 +10,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// simple test XML
|
// simple test XML
|
||||||
const xml string = `
|
const neededXML string = `
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<d:propfind xmlns:d="DAV:">
|
<d:propfind xmlns:d="DAV:">
|
||||||
<d:prop>
|
<d:prop>
|
||||||
@@ -35,7 +36,7 @@ func get_caldav_data(username string, password string) SimpleCalDavData {
|
|||||||
req, _ := http.NewRequest(
|
req, _ := http.NewRequest(
|
||||||
"PROPFIND",
|
"PROPFIND",
|
||||||
serverConfig.URL+"/dav/cal/"+convert_username_into_url(username),
|
serverConfig.URL+"/dav/cal/"+convert_username_into_url(username),
|
||||||
strings.NewReader(xml),
|
strings.NewReader(neededXML),
|
||||||
)
|
)
|
||||||
|
|
||||||
req.SetBasicAuth(username, password)
|
req.SetBasicAuth(username, password)
|
||||||
@@ -48,13 +49,19 @@ func get_caldav_data(username string, password string) SimpleCalDavData {
|
|||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
_, err = io.ReadAll(resp.Body)
|
body, err := io.ReadAll(resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var davResp MultiStatus
|
||||||
|
err = xml.Unmarshal(body, &davResp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return SimpleCalDavData{
|
return SimpleCalDavData{
|
||||||
DisplayName: "N/A",
|
DisplayName: davResp.Responses[0].PropStat[0].Prop.DisplayName,
|
||||||
Calandars: []string{},
|
Calandars: []string{},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-1
@@ -1,7 +1,10 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
read_config()
|
read_config()
|
||||||
init_dav_client()
|
init_dav_client()
|
||||||
get_caldav_data(serverConfig.Username, serverConfig.Password)
|
calDavData := get_caldav_data(serverConfig.Username, serverConfig.Password)
|
||||||
|
fmt.Printf("Users display name: {%s}\n", calDavData.DisplayName)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user