rearragne some stuff
This commit is contained in:
@@ -0,0 +1,60 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
// simple test XML
|
||||||
|
const xml string = `
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<d:propfind xmlns:d="DAV:">
|
||||||
|
<d:prop>
|
||||||
|
<d:displayname/>
|
||||||
|
<d:resourcetype/>
|
||||||
|
</d:prop>
|
||||||
|
</d:propfind>
|
||||||
|
`
|
||||||
|
|
||||||
|
var client *http.Client
|
||||||
|
|
||||||
|
func init_dav_client() {
|
||||||
|
client = &http.Client{}
|
||||||
|
}
|
||||||
|
|
||||||
|
type SimpleCalDavData struct {
|
||||||
|
DisplayName string
|
||||||
|
Calandars []string
|
||||||
|
}
|
||||||
|
|
||||||
|
// this makes stalwart assumptions
|
||||||
|
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),
|
||||||
|
)
|
||||||
|
|
||||||
|
req.SetBasicAuth(username, password)
|
||||||
|
req.Header.Set("Depth", "1")
|
||||||
|
req.Header.Set("Content-Type", "application/xml")
|
||||||
|
|
||||||
|
resp, err := client.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Print(err.Error())
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
_, err = io.ReadAll(resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return SimpleCalDavData{
|
||||||
|
DisplayName: "N/A",
|
||||||
|
Calandars: []string{},
|
||||||
|
}
|
||||||
|
}
|
||||||
+2
-45
@@ -1,50 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"log"
|
|
||||||
"net/http"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
read_config()
|
read_config()
|
||||||
|
init_dav_client()
|
||||||
client := &http.Client{}
|
get_caldav_data(serverConfig.Username, serverConfig.Password)
|
||||||
|
|
||||||
xml := `
|
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<d:propfind xmlns:d="DAV:">
|
|
||||||
<d:prop>
|
|
||||||
<d:displayname/>
|
|
||||||
<d:resourcetype/>
|
|
||||||
</d:prop>
|
|
||||||
</d:propfind>
|
|
||||||
`
|
|
||||||
|
|
||||||
body := strings.NewReader(xml)
|
|
||||||
|
|
||||||
req, _ := http.NewRequest(
|
|
||||||
"PROPFIND",
|
|
||||||
serverConfig.URL+"/dav/cal/"+convert_username_into_url(serverConfig.Username),
|
|
||||||
body,
|
|
||||||
)
|
|
||||||
|
|
||||||
req.SetBasicAuth(serverConfig.Username, serverConfig.Password)
|
|
||||||
req.Header.Set("Depth", "1")
|
|
||||||
req.Header.Set("Content-Type", "application/xml")
|
|
||||||
|
|
||||||
resp, err := client.Do(req)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Print(err.Error())
|
|
||||||
}
|
|
||||||
defer resp.Body.Close()
|
|
||||||
|
|
||||||
body2, err := io.ReadAll(resp.Body)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Println(string(body2))
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user