https://github.com/eoussama/freego
FreeStuff API Go Wrapper.
https://github.com/eoussama/freego
api-wrapper freestuff wrapper
Last synced: 5 months ago
JSON representation
FreeStuff API Go Wrapper.
- Host: GitHub
- URL: https://github.com/eoussama/freego
- Owner: eoussama
- License: apache-2.0
- Created: 2024-05-18T18:19:37.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2025-03-13T12:12:02.000Z (about 1 year ago)
- Last Synced: 2026-01-13T10:47:57.193Z (5 months ago)
- Topics: api-wrapper, freestuff, wrapper
- Language: Go
- Homepage:
- Size: 124 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Security: SECURITY.md
Awesome Lists containing this project
README
Freego
FreeStuff API Go Wrapper.
## Description
Freego is a go package that wrapps the [FreeStuff API](https://docs.freestuffbot.xyz/).
## Usage
### Prerequisites
* Go `1.22.3` or later
* A [FreeStuff](https://docs.freestuffbot.xyz/) API key.
### Installation
First, ensure you have the Freego package installed.
```sh
go get github.com/eoussama/freego
```
### Environment Variables
The Freego package can be configured using environment variables. Create a `.env` file after the [`.env.example`](./.env.example) file or set the following variables in your environment:
```txt
FREEGO_WEBHOOK_PORT=
FREEGO_WEBHOOK_ROUTE=
FREEGO_WEBHOOK_SECRET=
FREEGO_FREESTUFF_API_KEY=
```
### Example
```go
package main
import (
"fmt"
"github.com/eoussama/freego"
"github.com/eoussama/freego/src/enums"
"github.com/eoussama/freego/src/models"
)
func main() {
config := freego.Config(&models.Options{FreestuffPartner: false})
client, err := freego.Init(config)
if err != nil {
panic(fmt.Sprintf("[Init Error] %s", err))
}
// Pining the API
resp_ping, err := client.Ping()
if err != nil {
panic(fmt.Sprintf("[Ping Error] %s", err))
}
// Fetching all games
resp_games_all, err := client.GetGames(enums.FilterAll)
if err != nil {
panic(fmt.Sprintf("[All Games Error] %s", err))
}
// Fetching the free games
resp_games_free, err := client.GetGames(enums.FilterFree)
if err != nil {
panic(fmt.Sprintf("[Free Games Error] %s", err))
}
// Fetching the approved games
resp_games_approved, err := client.GetGames(enums.FilterApproved)
if err != nil {
panic(fmt.Sprintf("[Approved Games Error] %s", err))
}
// Fetching game info for the fetched free games, which localizations for french and german
resp_game_info, err := client.GetGameInfo(resp_games_free, []string{"fr-FR", "de-DE"})
if err != nil {
panic(fmt.Sprintf("[Game Info Error] %s", err))
}
fmt.Println("ping:", resp_ping)
fmt.Println("all games:", len(resp_games_all))
fmt.Println("free games:", len(resp_games_free))
fmt.Println("approved games:", len(resp_games_approved))
for i, game_info := range resp_game_info {
fmt.Println("game details info", i, ":", game_info)
}
// Event subscription
go func() {
err = client.On(enums.EventFreeGames, func(e *models.Event, err error) {
if err != nil {
panic(fmt.Sprintf("[On Free Games Error] %s", err))
}
fmt.Println("on free games", e.Data)
})
if err != nil {
panic(fmt.Sprintf("[On Free Games Error] %s", err))
}
}()
select {}
}
```
## Testing
### Webhook
For local testing, the project comes with a Docker image that's already set up with [smee](smee.io) for convenient event reception.
```sh
./smee.sh
```