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
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
@@ -9,7 +10,7 @@ import (
|
||||
)
|
||||
|
||||
// simple test XML
|
||||
const xml string = `
|
||||
const neededXML string = `
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<d:propfind xmlns:d="DAV:">
|
||||
<d:prop>
|
||||
@@ -35,7 +36,7 @@ func get_caldav_data(username string, password string) SimpleCalDavData {
|
||||
req, _ := http.NewRequest(
|
||||
"PROPFIND",
|
||||
serverConfig.URL+"/dav/cal/"+convert_username_into_url(username),
|
||||
strings.NewReader(xml),
|
||||
strings.NewReader(neededXML),
|
||||
)
|
||||
|
||||
req.SetBasicAuth(username, password)
|
||||
@@ -48,13 +49,19 @@ func get_caldav_data(username string, password string) SimpleCalDavData {
|
||||
}
|
||||
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 {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
return SimpleCalDavData{
|
||||
DisplayName: "N/A",
|
||||
DisplayName: davResp.Responses[0].PropStat[0].Prop.DisplayName,
|
||||
Calandars: []string{},
|
||||
}
|
||||
}
|
||||
|
||||
+4
-1
@@ -1,7 +1,10 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
read_config()
|
||||
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