Categorygithub.com/matrix-org/gomatrix
modulepackage
0.0.0-20220926102614-ceba4d9f7530
Repository: https://github.com/matrix-org/gomatrix.git
Documentation: pkg.go.dev

# README

gomatrix

GoDoc

A Golang Matrix client.

THIS IS UNDER ACTIVE DEVELOPMENT: BREAKING CHANGES ARE FREQUENT.

Contributing

All contributions are greatly appreciated!

How to report issues

Please check the current open issues for similar reports in order to avoid duplicates.

Some general guidelines:

  • Include a minimal reproducible example when possible.
  • Describe the expected behaviour and what actually happened including a full trace-back in case of exceptions.
  • Make sure to list details about your environment

Setting up your environment

If you intend to contribute to gomatrix you'll first need Go installed on your machine (version 1.12+ is required). Also, make sure to have golangci-lint properly set up since we use it for pre-commit hooks (for instructions on how to install it, check the official docs).

  • Fork gomatrix to your GitHub account by clicking the Fork button.

  • Clone the main repository (not your fork) to your local machine.

    $ git clone https://github.com/matrix-org/gomatrix
    $ cd gomatrix
    
  • Add your fork as a remote to push your contributions.Replace {username} with your username.

    git remote add fork https://github.com/{username}/gomatrix
    
  • Create a new branch to identify what feature you are working on.

    $ git fetch origin
    $ git checkout -b your-branch-name origin/master
    
  • Make your changes, including tests that cover any code changes you make, and run them as described below.

  • Execute pre-commit hooks by running

    <gomatrix dir>/hooks/pre-commit
    
  • Push your changes to your fork and create a pull request describing your changes.

    $ git push --set-upstream fork your-branch-name
    
  • Finally, create a pull request

How to run tests

You can run the test suite and example code with $ go test -v

Running Coverage

To run coverage, first generate the coverage report using go test

go test -v -cover -coverprofile=coverage.out

You can now show the generated report as a html page with go tool

go tool cover -html=coverage.out

# Functions

DecodeUserLocalpart decodes the given string back into the original input string.
DefaultFilter returns the default filter used by the Matrix server if no filter is provided in the request.
DefaultFilterPart returns the default filter part used by the Matrix server if no filter is provided in the request.
EncodeUserLocalpart encodes the given string into Matrix-compliant user ID localpart form.
ExtractUserLocalpart extracts the localpart portion of a user ID.
GetHTMLMessage returns an HTMLMessage with the body set to a stripped version of the provided HTML, in addition to the provided HTML.
NewClient creates a new Matrix Client ready for syncing.
NewDefaultSyncer returns an instantiated DefaultSyncer.
NewInMemoryStore constructs a new InMemoryStore.
NewPhoneIdentifier creates a new UserIdentifier with IDType set to "m.id.user".
NewRoom creates a new Room with the given ID.
NewThirdpartyIdentifier creates a new UserIdentifier with IDType set to "m.id.user".
NewUserIdentifier creates a new UserIdentifier with IDType set to "m.id.user".

# Structs

AudioInfo contains info about an file - http://matrix.org/docs/spec/client_server/r0.2.0.html#m-audio.
AudioMessage is an m.audio event - http://matrix.org/docs/spec/client_server/r0.2.0.html#m-audio.
Client represents a Matrix client.
DefaultSyncer is the default syncing implementation.
DiscoveryInformation is the JSON Response for https://matrix.org/docs/spec/client_server/r0.6.0#get-well-known-matrix-client and a part of the JSON Response for https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-login.
Event represents a single Matrix event.
FileInfo contains info about an file - http://matrix.org/docs/spec/client_server/r0.2.0.html#m-file.
FileMessage is an m.file event - http://matrix.org/docs/spec/client_server/r0.2.0.html#m-file.
Filter is used by clients to specify how the server should filter responses to e.g.
FilterPart is used to define filtering rules for specific categories of events.
An HTMLMessage is the contents of a Matrix HTML formated message event.
HTTPError An HTTP Error response, which may wrap an underlying native Go Error.
ImageInfo contains info about an image - http://matrix.org/docs/spec/client_server/r0.2.0.html#m-image.
ImageMessage is an m.image event.
InMemoryStore implements the Storer interface.
LocationMessage is an m.location event - http://matrix.org/docs/spec/client_server/r0.2.0.html#m-location.
PhoneIdentifier is the Identifier for https://matrix.org/docs/spec/client_server/r0.6.0#phone-number.
PublicRoom represents the information about a public room obtainable from the room directory.
ReqBanUser is the JSON request for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-ban.
ReqCreateRoom is the JSON request for https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-createroom.
ReqInvite3PID is the JSON request for https://matrix.org/docs/spec/client_server/r0.2.0.html#id57 It is also a JSON object used in https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-createroom.
ReqInviteUser is the JSON request for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-invite.
ReqKickUser is the JSON request for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-kick.
ReqLogin is the JSON request for http://matrix.org/docs/spec/client_server/r0.6.0.html#post-matrix-client-r0-login.
ReqRedact is the JSON request for http://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-rooms-roomid-redact-eventid-txnid.
ReqRegister is the JSON request for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-register.
ReqTyping is the JSON request for https://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-rooms-roomid-typing-userid.
ReqUnbanUser is the JSON request for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-unban.
RespBanUser is the JSON response for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-ban.
RespCreateFilter is the JSON response for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-user-userid-filter.
RespCreateRoom is the JSON response for https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-createroom.
RespError is the standard JSON error response from Homeservers.
RespForgetRoom is the JSON response for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-forget.
RespInviteUser is the JSON response for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-invite.
RespJoinedMembers is the JSON response for TODO-SPEC https://github.com/matrix-org/synapse/pull/1680.
RespJoinedRooms is the JSON response for TODO-SPEC https://github.com/matrix-org/synapse/pull/1680.
RespJoinRoom is the JSON response for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-join.
RespKickUser is the JSON response for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-kick.
RespLeaveRoom is the JSON response for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-leave.
RespLogin is the JSON response for http://matrix.org/docs/spec/client_server/r0.6.0.html#post-matrix-client-r0-login.
RespLogout is the JSON response for http://matrix.org/docs/spec/client_server/r0.6.0.html#post-matrix-client-r0-logout.
RespLogoutAll is the JSON response for https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-logout-all.
RespMediaUpload is the JSON response for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-media-r0-upload.
RespMessages is the JSON response for https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-rooms-roomid-messages.
RespPublicRooms is the JSON response for http://matrix.org/speculator/spec/HEAD/client_server/unstable.html#get-matrix-client-unstable-publicrooms.
RespRegister is the JSON response for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-register.
RespSendEvent is the JSON response for http://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-rooms-roomid-send-eventtype-txnid.
RespSync is the JSON response for http://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-sync.
RespTurnServer is the JSON response from a Turn Server.
RespTyping is the JSON response for https://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-rooms-roomid-typing-userid.
RespUnbanUser is the JSON response for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-unban.
RespUserDisplayName is the JSON response for https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-profile-userid-displayname.
RespUserInteractive is the JSON response for https://matrix.org/docs/spec/client_server/r0.2.0.html#user-interactive-authentication-api.
RespUserStatus is the JSON response for https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-presence-userid-status.
RespVersions is the JSON response for http://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-versions.
Room represents a single Matrix room.
RoomFilter is used to define filtering rules for room events.
TagContent contains the data for an m.tag message type https://matrix.org/docs/spec/client_server/r0.4.0.html#m-tag.
TagProperties contains the properties of a Tag.
TextMessage is the contents of a Matrix formated message event.
ThirdpartyIdentifier is the Identifier for https://matrix.org/docs/spec/client_server/r0.6.0#third-party-id.
ThumbnailInfo contains info about an thumbnail image - http://matrix.org/docs/spec/client_server/r0.2.0.html#m-image.
UserIdentifier is the Identifier for https://matrix.org/docs/spec/client_server/r0.6.0#matrix-user-id.
VideoInfo contains info about a video - http://matrix.org/docs/spec/client_server/r0.2.0.html#m-video.
VideoMessage is an m.video - http://matrix.org/docs/spec/client_server/r0.2.0.html#m-video.

# Interfaces

Identifier is the interface for https://matrix.org/docs/spec/client_server/r0.6.0#identifier-types.
Storer is an interface which must be satisfied to store client data.
Syncer represents an interface that must be satisfied in order to do /sync requests on a client.

# Type aliases

OnEventListener can be used with DefaultSyncer.OnEventType to be informed of incoming events.