Go wrapper for the DesuMe Web API
- 🔄 Easy-to-use wrapper for DesuMe API
- ⚙️ Configurable HTTP client with timeout and connection pool settings
- 🛡️ Built-in rate limiting to prevent API abuse
- 🌐 Support for all major API endpoints
- 🎛️ Customizable request parameters
- 📝 Ability to set and modify headers dynamically
To install the library, simply run:
go get github.com/vladis1av/desume-client-go
First, import the package and create a new client:
import (
"github.com/vladis1av/desume-client-go/desume"
"time"
)
// Create with optional settings
client := desume.NewClient(
desume.WithBaseURL("https://desu.me/manga/api/"), // default https://desu.win/manga/api/
desume.WithDisableCompression(true),
desume.WithIdleConnTimeout(60*time.Second),
desume.WithTimeout(30*time.Second),
desume.WithMaxIdleConns(50),
desume.WithRateLimiter(2, 1),
// Recommended limit to prevent API blocking: // 3 requests per second with the possibility of briefly exceeding 1 request
)
Use WithHeaders to set a set of headers when creating the client. These headers will be used in all requests and can be overridden by using SetHeader:
client := desume.NewClient(
desume.WithHeaders(http.Header{
"User-Agent": []string{"My-App/1.0"},
"X-Custom-Header": []string{"CustomValue"},
}),
)
You can dynamically change or add headers after the client is created using SetHeader:
client.SetHeader("Authorization", "Bearer token")
To fetch information about a specific manga:
manga, err := client.GetMangaById(ctx, 1)
if err != nil {
log.Fatalf("Failed to get manga: %v", err)
}
fmt.Printf("Manga: %+v\n", manga.Response.ID)
To get a list of manga with default parameters:
mangas, err := client.GetMangas(ctx, desume.GetDefaultMangaFilterParams())
if err != nil {
log.Fatalf("Failed to get mangas: %v", err)
}
fmt.Printf("First manga in list: %+v\n", mangas.Response[0].ID)
To fetch manga information including chapters:
mangaChapter, err := client.GetMangaChapter(ctx, 1, 1)
if err != nil {
log.Fatalf("Failed to get manga chapter: %v", err)
}
fmt.Printf("Manga chapter: %+v\n", mangaChapter.Response.ID)
To get a filtered list of manga:
filteredMangas, err := client.GetMangas(ctx, desume.GetMangaFilterParams("1", "5", desume.OrderByUpdated, desume.KindManga, "game", "bleach"))
if err != nil {
log.Fatalf("Failed to get filtered mangas: %v", err)
}
fmt.Printf("First filtered manga: %+v\n", filteredMangas.Response[0].ID)
The client includes a built-in rate limiter. You can handle rate limit errors like this:
manga, err := client.GetMangaById(ctx, 1)
if err == desume.ErrRateLimitExceeded {
log.Println("Rate limit exceeded, waiting before retry...")
time.Sleep(time.Second)
manga, err = client.GetMangaById(ctx, 1)
}
For more detailed information about the available methods and options, please refer to the GoDoc documentation.
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.