client

package module
v0.0.0-...-2d1dba8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 21, 2024 License: MIT Imports: 8 Imported by: 0

README

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

  • Go (1.23.1 or later, older versions could work under the assumption of no guarantee)

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))
  1. Upload an app:
	// Upload new app
	metadata := client.AppMetadata{
		Name: "Camera",
		Ver:  "6",
		Info: "This is a camera app",
		Pub:  "matu6968",
	}
	newApp, err := client.UploadApp(metadata, "./index.js", "123456789011") // custom app id is optional
	if err != nil {
		log.Fatal("Failed to upload app:", err)
	}
	fmt.Printf("Uploaded app with ID: %s\n", newApp.AppID)
  1. Edit an app:
	// Edit app
	metadata := client.AppMetadata{ // only specify what you need
	    Name: "Camera",
	    Ver:  "7",
	    Info: "This is a new camera app",
	    Pub:  "matu6968",
	}
	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")
  1. 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")

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type App

type App struct {
	Name  string `json:"name"`
	Ver   string `json:"ver"`
	AppID string `json:"appid"`
	Info  string `json:"info"`
	Pub   string `json:"pub"`
	Path  string `json:"path"`
}

type AppMetadata

type AppMetadata struct {
	Name string `json:"name"`
	Ver  string `json:"ver"`
	Info string `json:"info"`
	Pub  string `json:"pub"`
}

type AppStoreClient

type AppStoreClient struct {
	BaseURL    string
	AuthToken  string
	HttpClient *http.Client
}

func NewClient

func NewClient(baseURL, authToken string) *AppStoreClient

NewClient creates a new AppStore client

func (*AppStoreClient) DeleteApp

func (c *AppStoreClient) DeleteApp(appID string) error

DeleteApp removes an app from the store

func (*AppStoreClient) EditApp

func (c *AppStoreClient) EditApp(appID string, metadata AppMetadata, filePath string) error

EditApp updates an existing app

func (*AppStoreClient) GetApps

func (c *AppStoreClient) GetApps() ([]App, error)

GetApps retrieves all apps from the store

func (*AppStoreClient) UploadApp

func (c *AppStoreClient) UploadApp(metadata AppMetadata, filePath string, customAppID string) (*App, error)

UploadApp uploads a new app to the store with an optional custom app ID

func (*AppStoreClient) UploadAppSimple

func (c *AppStoreClient) UploadAppSimple(metadata AppMetadata, filePath string) (*App, error)

Backwards compatibility wrapper

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL