move some stuff around

This commit is contained in:
2026-07-24 21:11:33 -07:00
parent 0064294c3c
commit 98c8b453a0
3 changed files with 36 additions and 28 deletions
+28
View File
@@ -0,0 +1,28 @@
package main
import (
"encoding/json"
"fmt"
"os"
)
type Config struct {
URL string `json:"url"`
Username string `json:"username"`
Password string `json:"password"`
}
var serverConfig Config
func read_config() {
file, err := os.ReadFile("config.json")
if err != nil {
fmt.Print(err.Error())
return
}
err = json.Unmarshal(file, &serverConfig)
if err != nil {
fmt.Print(err.Error())
}
}
+8
View File
@@ -0,0 +1,8 @@
package main
import "strings"
func convert_username_into_url(username string) string {
result := strings.ReplaceAll(username, "@", "%40")
return result
}
+48
View File
@@ -0,0 +1,48 @@
package main
import (
"fmt"
"io"
"log"
"net/http"
"strings"
)
func main() {
read_config()
client := &http.Client{}
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))
}