webdesk-appmarket-golang/README.md

88 lines
1.9 KiB
Markdown
Raw Permalink Normal View History

2024-11-21 00:45:22 +01:00
# WebDesk 3rd party App Market client API for Go
This allows you to make custom (known as 3rd party) App Market server clients for your intended purpose.
## Features
- Listing currently uploaded apps
- Uploading new apps
- Editing app info
- Delete apps
## Prerequisites
2024-11-21 02:17:39 +01:00
- Go (1.23.1 or later, older versions could work under the assumption of no guarantee)
2024-11-21 00:45:22 +01:00
## Usage
Import in your Go code:
```
import (
"git.fluffy.pw/matu6968/webdesk-appmarket-golang"
)
```
# Configuration
In the .env file this is the only thing you can set
```
AUTH_TOKEN=bearer-token-here # Put your token generated from the server .env file
```
# API usage
1. List uploaded apps:
```
// Create new client
c := client.NewClient("http://localhost:8080", os.Getenv("AUTH_TOKEN"))
// List all apps
apps, err := c.GetApps()
if err != nil {
log.Fatal("Failed to get apps:", err)
}
fmt.Printf("Found %d apps\n", len(apps))
```
2. Upload an app:
```
// Upload new app
metadata := client.AppMetadata{
Name: "Camera",
Ver: "6",
Info: "This is a camera app",
Pub: "matu6968",
}
2024-11-21 12:11:12 +01:00
newApp, err := client.UploadApp(metadata, "./index.js", "123456789011") // custom app id is optional
2024-11-21 00:45:22 +01:00
if err != nil {
log.Fatal("Failed to upload app:", err)
}
fmt.Printf("Uploaded app with ID: %s\n", newApp.AppID)
```
3. Edit an app:
```
// Edit app
2024-11-21 00:55:31 +01:00
metadata := client.AppMetadata{ // only specify what you need
Name: "Camera",
Ver: "7",
Info: "This is a new camera app",
Pub: "matu6968",
}
2024-11-21 00:45:22 +01:00
err = c.EditApp(newApp.AppID, metadata, "./index.js") // replace newApp.AppID with the app id you want to delete
if err != nil {
log.Fatal("Failed to edit app:", err)
}
fmt.Println("App updated successfully")
```
4. Delete an app:
```
// Delete app
err = c.DeleteApp(newApp.AppID) // replace newApp.AppID with the app id you want to delete
if err != nil {
log.Fatal("Failed to delete app:", err)
}
fmt.Println("App deleted successfully")
```