Remove websocket example because the websocket has been removed from lemmy
This commit is contained in:
parent
058b3879ae
commit
329bf27ffd
@ -7,7 +7,6 @@ Go bindings to the [Lemmy](https://join-lemmy.org) API, automatically generated
|
||||
Examples:
|
||||
|
||||
- HTTP: [examples/http](examples/http)
|
||||
- WebSocket: [examples/websocket](examples/websocket)
|
||||
|
||||
### How to generate
|
||||
|
||||
@ -35,4 +34,4 @@ Execute the generator:
|
||||
./gen -out-dir .
|
||||
```
|
||||
|
||||
And that's it! Your generated code should be ready for use.
|
||||
And that's it! Your generated code should be ready for use.
|
||||
|
@ -1,66 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
|
||||
"go.elara.ws/go-lemmy"
|
||||
"go.elara.ws/go-lemmy/types"
|
||||
)
|
||||
|
||||
func main() {
|
||||
ctx := context.Background()
|
||||
|
||||
c, err := lemmy.NewWebSocket("https://lemmygrad.ml")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
err = c.ClientLogin(ctx, types.Login{
|
||||
UsernameOrEmail: "user@example.com",
|
||||
Password: `TestPwd`,
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// If nil is passed as data, go-lemmy will just send
|
||||
// the auth token, which is all that's needed for
|
||||
// the UserJoin operation.
|
||||
c.Request(types.UserOperationUserJoin, nil)
|
||||
|
||||
// Subscribe to all communities
|
||||
c.Request(types.UserOperationCommunityJoin, types.CommunityJoin{
|
||||
CommunityID: 0,
|
||||
})
|
||||
|
||||
go handleErrors(c)
|
||||
handleResponses(c)
|
||||
}
|
||||
|
||||
func handleResponses(c *lemmy.WSClient) {
|
||||
for res := range c.Responses() {
|
||||
if res.IsOneOf(types.UserOperationCRUDCreateComment) {
|
||||
var data types.CommentResponse
|
||||
err := lemmy.DecodeResponse(res.Data, &data)
|
||||
if err != nil {
|
||||
log.Println("Error decoding response:", err)
|
||||
continue
|
||||
}
|
||||
|
||||
err = c.Request(types.UserOperationCreateCommentLike, types.CreateCommentLike{
|
||||
CommentID: data.CommentView.Comment.ID,
|
||||
})
|
||||
if err != nil {
|
||||
log.Println("Error decoding response:", err)
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func handleErrors(c *lemmy.WSClient) {
|
||||
for err := range c.Errors() {
|
||||
log.Println("Error decoding response:", err)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user