go-lemmy/README.md

59 lines
1.0 KiB
Markdown
Raw Normal View History

2022-12-10 17:17:16 +00:00
# Go-Lemmy
2022-12-10 17:52:09 +00:00
[![Go Reference](https://pkg.go.dev/badge/go.arsenm.dev/go-lemmy.svg)](https://pkg.go.dev/go.arsenm.dev/go-lemmy)
2023-01-07 23:15:49 +00:00
Go bindings to the [Lemmy](https://join-lemmy.org) API, automatically generated directly from Lemmy's source code using the generator in [cmd/gen](cmd/gen).
2022-12-10 17:17:16 +00:00
Example:
```go
ctx := context.Background()
c, err := lemmy.New("https://lemmygrad.ml")
2022-12-10 17:17:16 +00:00
if err != nil {
panic(err)
2022-12-10 17:17:16 +00:00
}
err = c.ClientLogin(ctx, types.Login{
UsernameOrEmail: "user@example.com",
Password: `TestPwd`,
2022-12-10 17:17:16 +00:00
})
if err != nil {
panic(err)
2022-12-10 17:17:16 +00:00
}
_, err = c.SaveUserSettings(ctx, types.SaveUserSettings{
BotAccount: types.NewOptional(true),
2022-12-10 17:17:16 +00:00
})
if err != nil {
panic(err)
2022-12-10 17:17:16 +00:00
}
2023-01-07 23:15:49 +00:00
```
### How to generate
First, build the generator:
```bash
go build ./cmd/gen
```
Clone Lemmy's source code at whatever version you need:
```bash
git clone https://github.com/LemmyNet/lemmy -b 0.16.7
```
Remove all the existing generated code:
```bash
rm **/*.gen.go
```
Execute the generator:
```bash
./gen -out-dir .
```
And that's it! Your generated code should be ready for use.