Documentation
¶
Overview ¶
Package etherpadlite provides an interface for Etherpad-Lite's HTTP API written entirely in Go. The API documentation can be found at https://github.com/ether/etherpad-lite/wiki/HTTP-API. To use it create an instance of etherpadlite.EtherpadLite and call the API methods on it, for example CreatePad(nil, padID, text). If a parameter is optional, like text is in createPad, simply set the value to etherpadlite.OptionalParam. If there is a parameter with a default value, like copyPad(sourceID, destinationID[, force=false]), setting the parameter to OptionalParam will set the value to the default value.
All methods return a Response and an error (!= nil if something went wrong). The first argument of all methods is always a Context ctx. If set to a non-nil context the method will return nil and an error != nil when the context gets cancelled. If you don't want to use any context stuff just set it to nil. This is however not the best practice to set the context, better set it to context.Background or context.TODO if you don't want to use the context.
It is safe to call the API methods simultaneously from multiple goroutines.
I didn't document the methods since they're documented very well on the etherpad homepage: https://etherpad.org/doc/v1.7.5/#index_http_api
Index ¶
- Constants
- type EtherpadError
- type EtherpadLite
- func (pad *EtherpadLite) AppendText(ctx context.Context, padID, text interface{}) (*Response, error)
- func (pad *EtherpadLite) CheckToken(ctx context.Context) (*Response, error)
- func (pad *EtherpadLite) CopyPad(ctx context.Context, sourceID, destinationID, force interface{}) (*Response, error)
- func (pad *EtherpadLite) CreateAuthor(ctx context.Context, name interface{}) (*Response, error)
- func (pad *EtherpadLite) CreateAuthorIfNotExistsFor(ctx context.Context, authorMapper, name interface{}) (*Response, error)
- func (pad *EtherpadLite) CreateDiffHTML(ctx context.Context, padID, startRev, endRev interface{}) (*Response, error)
- func (pad *EtherpadLite) CreateGroup(ctx context.Context) (*Response, error)
- func (pad *EtherpadLite) CreateGroupIfNotExistsFor(ctx context.Context, groupMapper interface{}) (*Response, error)
- func (pad *EtherpadLite) CreateGroupPad(ctx context.Context, groupID, padName, text interface{}) (*Response, error)
- func (pad *EtherpadLite) CreatePad(ctx context.Context, padID, text interface{}) (*Response, error)
- func (pad *EtherpadLite) CreateSession(ctx context.Context, groupID, authorID, validUntil interface{}) (*Response, error)
- func (pad *EtherpadLite) DeleteGroup(ctx context.Context, groupID interface{}) (*Response, error)
- func (pad *EtherpadLite) DeletePad(ctx context.Context, padID interface{}) (*Response, error)
- func (pad *EtherpadLite) DeleteSession(ctx context.Context, sessionID interface{}) (*Response, error)
- func (pad *EtherpadLite) GetAttributePool(ctx context.Context, padID interface{}) (*Response, error)
- func (pad *EtherpadLite) GetAuthorName(ctx context.Context, authorID interface{}) (*Response, error)
- func (pad *EtherpadLite) GetChatHead(ctx context.Context, padID interface{}) (*Response, error)
- func (pad *EtherpadLite) GetChatHistory(ctx context.Context, padID, start, end interface{}) (*Response, error)
- func (pad *EtherpadLite) GetHTML(ctx context.Context, padID, rev interface{}) (*Response, error)
- func (pad *EtherpadLite) GetLastEdited(ctx context.Context, padID interface{}) (*Response, error)
- func (pad *EtherpadLite) GetPadID(ctx context.Context, readOnlyID interface{}) (*Response, error)
- func (pad *EtherpadLite) GetPublicStatus(ctx context.Context, padID interface{}) (*Response, error)
- func (pad *EtherpadLite) GetReadOnlyID(ctx context.Context, padID interface{}) (*Response, error)
- func (pad *EtherpadLite) GetRevisionChangeset(ctx context.Context, padID, rev interface{}) (*Response, error)
- func (pad *EtherpadLite) GetRevisionsCount(ctx context.Context, padID interface{}) (*Response, error)
- func (pad *EtherpadLite) GetSavedRevisionsCount(ctx context.Context, padID interface{}) (*Response, error)
- func (pad *EtherpadLite) GetSessionInfo(ctx context.Context, sessionID interface{}) (*Response, error)
- func (pad *EtherpadLite) GetText(ctx context.Context, padID, rev interface{}) (*Response, error)
- func (pad *EtherpadLite) IsPasswordProtected(ctx context.Context, padID interface{}) (*Response, error)
- func (pad *EtherpadLite) ListAllGroups(ctx context.Context) (*Response, error)
- func (pad *EtherpadLite) ListAllPads(ctx context.Context) (*Response, error)
- func (pad *EtherpadLite) ListAuthorsOfPad(ctx context.Context, padID interface{}) (*Response, error)
- func (pad *EtherpadLite) ListPads(ctx context.Context, groupID interface{}) (*Response, error)
- func (pad *EtherpadLite) ListPadsOfAuthor(ctx context.Context, authorID interface{}) (*Response, error)
- func (pad *EtherpadLite) ListSavedRevisions(ctx context.Context, padID interface{}) (*Response, error)
- func (pad *EtherpadLite) ListSessionsOfAuthor(ctx context.Context, authorID interface{}) (*Response, error)
- func (pad *EtherpadLite) ListSessionsOfGroup(ctx context.Context, groupID interface{}) (*Response, error)
- func (pad *EtherpadLite) MovePad(ctx context.Context, sourceID, destinationID, force interface{}) (*Response, error)
- func (pad *EtherpadLite) PadUsers(ctx context.Context, padID interface{}) (*Response, error)
- func (pad *EtherpadLite) PadUsersCount(ctx context.Context, padID interface{}) (*Response, error)
- func (pad *EtherpadLite) RestoreRevision(ctx context.Context, padId, rev interface{}) (*Response, error)
- func (pad *EtherpadLite) SaveRevision(ctx context.Context, padID, rev interface{}) (*Response, error)
- func (pad *EtherpadLite) SendClientsMessage(ctx context.Context, padID, msg interface{}) (*Response, error)
- func (pad *EtherpadLite) SetHTML(ctx context.Context, padID, html interface{}) (*Response, error)
- func (pad *EtherpadLite) SetPassword(ctx context.Context, padID, password interface{}) (*Response, error)
- func (pad *EtherpadLite) SetPublicStatus(ctx context.Context, padID, publicStatus interface{}) (*Response, error)
- func (pad *EtherpadLite) SetText(ctx context.Context, padID, text interface{}) (*Response, error)
- type Response
- type ReturnCode
Constants ¶
const ( // CurrentVersion is the default version to use. CurrentVersion = "1.2.13" // OptionalParam is a constant used to identify an optional parameter we don't // want to use. OptionalParam optionalParamType = 0 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type EtherpadError ¶
type EtherpadError struct {
// contains filtered or unexported fields
}
EtherpadError is an error returned by all methods if EtherpadLite.RaiseEtherpadErrors is true. It reports any internal error returned by calling the HTTP API of etherpad, signaling that the ReturnCode is not EverythingOk.
func NewEtherpadError ¶
func NewEtherpadError(code ReturnCode, message string) EtherpadError
NewEtherpadError returns a new EtherpadError. The code should be != EverythingOk and the message is the error message returned by the HTTP API.
func (EtherpadError) Error ¶
func (e EtherpadError) Error() string
Error returns the error as a string.
type EtherpadLite ¶
type EtherpadLite struct { // APIVersion is the api version to use. It defaults to "1.2.13" in // NewEtherpadLite. APIVersion string // BaseParams are the parameter that are required in each request, i.e. // will be sent in each request. // The entry BaseParams["apikey"] = YOUR-API-KEY // should always be present. // NewEtherpadLite will take care of this. BaseParams map[string]interface{} // BaseURL is the URL pointing to the API of your pad, i.e. // http://pad.domain/api // It defaults to http://localhost:9001/api in NewEtherpadLite. BaseURL string // Client is used to send the GET requests to the API. // Set the values as required. // It defaults to the http.DefaultClient in NewEtherpadLite. Client *http.Client // RaiseEtherpadErrors specifies if errors returned by etherpad should be // returned as errors in Go or should be handled by the caller by checking // the response code. // It defaults to False. // By setting it to true the calls to all functions will return an error // for all responses with Response.Code != EverythingOk. // In this case an instance of EtherpadError is raised. RaiseEtherpadErrors bool }
EtherpadLite is a struct that is used to connect to the etherpadlite API.
func NewEtherpadLite ¶
func NewEtherpadLite(apiKey string) *EtherpadLite
NewEtherpadLite creates a new EtherpadLite instance given the mandatory apiKey. Create a new instance with this method and then configure it if you must.
func (*EtherpadLite) AppendText ¶
func (pad *EtherpadLite) AppendText(ctx context.Context, padID, text interface{}) (*Response, error)
func (*EtherpadLite) CheckToken ¶
func (pad *EtherpadLite) CheckToken(ctx context.Context) (*Response, error)
func (*EtherpadLite) CopyPad ¶
func (pad *EtherpadLite) CopyPad(ctx context.Context, sourceID, destinationID, force interface{}) (*Response, error)
func (*EtherpadLite) CreateAuthor ¶
func (pad *EtherpadLite) CreateAuthor(ctx context.Context, name interface{}) (*Response, error)
func (*EtherpadLite) CreateAuthorIfNotExistsFor ¶
func (pad *EtherpadLite) CreateAuthorIfNotExistsFor(ctx context.Context, authorMapper, name interface{}) (*Response, error)
func (*EtherpadLite) CreateDiffHTML ¶
func (pad *EtherpadLite) CreateDiffHTML(ctx context.Context, padID, startRev, endRev interface{}) (*Response, error)
func (*EtherpadLite) CreateGroup ¶
func (pad *EtherpadLite) CreateGroup(ctx context.Context) (*Response, error)
func (*EtherpadLite) CreateGroupIfNotExistsFor ¶
func (pad *EtherpadLite) CreateGroupIfNotExistsFor(ctx context.Context, groupMapper interface{}) (*Response, error)
func (*EtherpadLite) CreateGroupPad ¶
func (pad *EtherpadLite) CreateGroupPad(ctx context.Context, groupID, padName, text interface{}) (*Response, error)
func (*EtherpadLite) CreatePad ¶
func (pad *EtherpadLite) CreatePad(ctx context.Context, padID, text interface{}) (*Response, error)
func (*EtherpadLite) CreateSession ¶
func (pad *EtherpadLite) CreateSession(ctx context.Context, groupID, authorID, validUntil interface{}) (*Response, error)
func (*EtherpadLite) DeleteGroup ¶
func (pad *EtherpadLite) DeleteGroup(ctx context.Context, groupID interface{}) (*Response, error)
func (*EtherpadLite) DeletePad ¶
func (pad *EtherpadLite) DeletePad(ctx context.Context, padID interface{}) (*Response, error)
func (*EtherpadLite) DeleteSession ¶
func (pad *EtherpadLite) DeleteSession(ctx context.Context, sessionID interface{}) (*Response, error)
func (*EtherpadLite) GetAttributePool ¶
func (pad *EtherpadLite) GetAttributePool(ctx context.Context, padID interface{}) (*Response, error)
func (*EtherpadLite) GetAuthorName ¶
func (pad *EtherpadLite) GetAuthorName(ctx context.Context, authorID interface{}) (*Response, error)
func (*EtherpadLite) GetChatHead ¶
func (pad *EtherpadLite) GetChatHead(ctx context.Context, padID interface{}) (*Response, error)
func (*EtherpadLite) GetChatHistory ¶
func (pad *EtherpadLite) GetChatHistory(ctx context.Context, padID, start, end interface{}) (*Response, error)
func (*EtherpadLite) GetHTML ¶
func (pad *EtherpadLite) GetHTML(ctx context.Context, padID, rev interface{}) (*Response, error)
func (*EtherpadLite) GetLastEdited ¶
func (pad *EtherpadLite) GetLastEdited(ctx context.Context, padID interface{}) (*Response, error)
func (*EtherpadLite) GetPadID ¶
func (pad *EtherpadLite) GetPadID(ctx context.Context, readOnlyID interface{}) (*Response, error)
func (*EtherpadLite) GetPublicStatus ¶
func (pad *EtherpadLite) GetPublicStatus(ctx context.Context, padID interface{}) (*Response, error)
func (*EtherpadLite) GetReadOnlyID ¶
func (pad *EtherpadLite) GetReadOnlyID(ctx context.Context, padID interface{}) (*Response, error)
func (*EtherpadLite) GetRevisionChangeset ¶
func (pad *EtherpadLite) GetRevisionChangeset(ctx context.Context, padID, rev interface{}) (*Response, error)
func (*EtherpadLite) GetRevisionsCount ¶
func (pad *EtherpadLite) GetRevisionsCount(ctx context.Context, padID interface{}) (*Response, error)
func (*EtherpadLite) GetSavedRevisionsCount ¶
func (pad *EtherpadLite) GetSavedRevisionsCount(ctx context.Context, padID interface{}) (*Response, error)
func (*EtherpadLite) GetSessionInfo ¶
func (pad *EtherpadLite) GetSessionInfo(ctx context.Context, sessionID interface{}) (*Response, error)
func (*EtherpadLite) GetText ¶
func (pad *EtherpadLite) GetText(ctx context.Context, padID, rev interface{}) (*Response, error)
func (*EtherpadLite) IsPasswordProtected ¶
func (pad *EtherpadLite) IsPasswordProtected(ctx context.Context, padID interface{}) (*Response, error)
func (*EtherpadLite) ListAllGroups ¶
func (pad *EtherpadLite) ListAllGroups(ctx context.Context) (*Response, error)
func (*EtherpadLite) ListAllPads ¶
func (pad *EtherpadLite) ListAllPads(ctx context.Context) (*Response, error)
func (*EtherpadLite) ListAuthorsOfPad ¶
func (pad *EtherpadLite) ListAuthorsOfPad(ctx context.Context, padID interface{}) (*Response, error)
func (*EtherpadLite) ListPads ¶
func (pad *EtherpadLite) ListPads(ctx context.Context, groupID interface{}) (*Response, error)
func (*EtherpadLite) ListPadsOfAuthor ¶
func (pad *EtherpadLite) ListPadsOfAuthor(ctx context.Context, authorID interface{}) (*Response, error)
func (*EtherpadLite) ListSavedRevisions ¶
func (pad *EtherpadLite) ListSavedRevisions(ctx context.Context, padID interface{}) (*Response, error)
func (*EtherpadLite) ListSessionsOfAuthor ¶
func (pad *EtherpadLite) ListSessionsOfAuthor(ctx context.Context, authorID interface{}) (*Response, error)
func (*EtherpadLite) ListSessionsOfGroup ¶
func (pad *EtherpadLite) ListSessionsOfGroup(ctx context.Context, groupID interface{}) (*Response, error)
func (*EtherpadLite) MovePad ¶
func (pad *EtherpadLite) MovePad(ctx context.Context, sourceID, destinationID, force interface{}) (*Response, error)
func (*EtherpadLite) PadUsers ¶
func (pad *EtherpadLite) PadUsers(ctx context.Context, padID interface{}) (*Response, error)
func (*EtherpadLite) PadUsersCount ¶
func (pad *EtherpadLite) PadUsersCount(ctx context.Context, padID interface{}) (*Response, error)
func (*EtherpadLite) RestoreRevision ¶
func (pad *EtherpadLite) RestoreRevision(ctx context.Context, padId, rev interface{}) (*Response, error)
func (*EtherpadLite) SaveRevision ¶
func (pad *EtherpadLite) SaveRevision(ctx context.Context, padID, rev interface{}) (*Response, error)
func (*EtherpadLite) SendClientsMessage ¶
func (pad *EtherpadLite) SendClientsMessage(ctx context.Context, padID, msg interface{}) (*Response, error)
func (*EtherpadLite) SetHTML ¶
func (pad *EtherpadLite) SetHTML(ctx context.Context, padID, html interface{}) (*Response, error)
func (*EtherpadLite) SetPassword ¶
func (pad *EtherpadLite) SetPassword(ctx context.Context, padID, password interface{}) (*Response, error)
func (*EtherpadLite) SetPublicStatus ¶
func (pad *EtherpadLite) SetPublicStatus(ctx context.Context, padID, publicStatus interface{}) (*Response, error)
type Response ¶
type Response struct { Code ReturnCode Message string Data map[string]interface{} }
Response is the response from the etherpad API. See https://github.com/ether/etherpad-lite/wiki/HTTP-API
type ReturnCode ¶
type ReturnCode int
ReturnCode is the code return by the etherpad API, see API documentation for more details.
const ( EverythingOk ReturnCode = iota WrongParameters InternalError NoSuchFunction WrongAPIKey )
func (ReturnCode) String ¶
func (c ReturnCode) String() string