dram.me

使用Matrix的Go客户端库

Matrix有一个简单的Go客户端库gomatrix,以下是一个简单的示例,显示用户加入的聊天室:

package main

import (
	"fmt"
	matrix "github.com/matrix-org/gomatrix"
)

func main() {
	if cli, e := matrix.NewClient("https://SERVER", "@USER:SERVER", "ACCESS_TOKEN"); e == nil {
		url := cli.BuildURL("joined_rooms")

		var resp *struct {
			JoinedRooms []string `json:"joined_rooms"`
		}

		if _, e := cli.MakeRequest("GET", url, nil, &resp); e == nil {
			fmt.Println(resp)
		} else {
			fmt.Println("MakeRequest failed: ", e)
			return
		}
	} else {
		fmt.Println("NewClient failed: ", e)
		return
	}
}