Skip to content

discloud/discloud-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Discloud API Go

This SDK is still in beta phase, any bug or error just join the discloud discord and talk to @failed


Links


Table of Contents

Getting Started

Prerequisites

  • Go 1.21 or higher.

Installation

go get github.com/discloud/discloud-go

Usage

Here is a simple example of how to get your user information:

package main

import (
	"fmt"
	"log"

	discloud "github.com/discloud/discloud-go/discloud"
)

func main() {
	// Login with your Discloud API token
	client := discloud.Login("YOUR_API_TOKEN")

	// Get user information
	user, err := client.User().Info()
	if err != nil {
		log.Fatalf("Error getting user information: %v", err)
	}

	fmt.Printf("User ID: %s
", user.UserID)
	fmt.Printf("Username: %s
", user.Username)
	fmt.Printf("Plan: %s
", user.Plan)
}

API Reference

The Discloud API Go Wrapper is organized into the following modules:

User

The user module allows you to manage your Discloud account.

  • Info(): Get your user information.
  • SetLocale(locale string): Set your preferred locale.

App

The app module allows you to manage your Discloud applications.

  • Upload(filePath string): Upload a new application.
  • Info(appID string): Get information about an application.
  • Status(appID string): Get the status of an application.
  • Logs(appID string): Get the logs of an application.
  • Backup(appID string): Get a backup of an application.
  • Start(appID string): Start an application.
  • Restart(appID string): Restart an application.
  • Stop(appID string): Stop an application.
  • ChangeRAM(appID string, ram int): Change the RAM of an application.
  • Commit(appID string, filePath string): Commit changes to an application.
  • Delete(appID string): Delete an application.
  • ListAll(): List all your applications.

Team

The team module allows you to manage your Discloud team.

  • GetTeam(appID string): Get team information for an application.
  • AddMember(appID string, memberID string, perms []string): Add a member to your team.
  • EditMember(appID string, memberID string, perms []string): Edit the permissions of a team member.
  • RemoveMember(appID string, memberID string): Remove a member from your team.

Examples

Here are some examples of how to use the Discloud API Go Wrapper.

User Examples

package main

import (
	"fmt"
	"log"

	discloud "github.com/discloud/discloud-go/discloud"
)

func main() {
	token := "YOUR_API_TOKEN"
	client := discloud.Login(token)
	user := discloud.User(client)

	// Get user information
	info, err := user.Info()
	if err != nil {
		log.Fatalf("Error getting user info: %v", err)
	}
	fmt.Printf("User information: %+v
", info)

	// Change language/locale
	localeResp, err := user.SetLocale("pt-BR")
	if err != nil {
		log.Fatalf("Error changing locale: %v", err)
	}
	fmt.Printf("Change locale response: %+v
", localeResp)
}

App Examples

package main

import (
	"fmt"
	"log"

	discloud "github.com/discloud/discloud-go/discloud"
)

func main() {
	token := "YOUR_API_TOKEN"
	client := discloud.Login(token)
	app := discloud.App(client)

	appId := "YOUR_APP_ID"

	// Upload app
	upload, err := app.Upload("path/to/your/app.zip")
	if err != nil {
		log.Fatalf("Error uploading: %v", err)
	}
	fmt.Println("Upload Response:", string(upload))

	// Get app info
	info, err := app.Info(appId)
	if err != nil {
		log.Fatalf("Error getting app info: %v", err)
	}
	fmt.Printf("App info: %+v
", info)

	// Get app status
	status, err := app.Status(appId)
	if err != nil {
		log.Fatalf("Error getting app status: %v", err)
	}
	fmt.Printf("App status: %+v
", status)

	// Start the app
	startResp, err := app.Start(appId)
	if err != nil {
		log.Fatalf("Error starting app: %v", err)
	}
	fmt.Println("Start Response:", string(startResp))

	// Commit file to the app
	commitResp, err := app.Commit(appId, "path/to/your/app.zip")
	if err != nil {
		log.Fatalf("Error committing: %v", err)
	}
	fmt.Println("Commit Response:", string(commitResp))

	// Change RAM
	changeRamResp, err := app.ChangeRAM(appId, 1024)
	if err != nil {
		log.Fatalf("Error changing RAM: %v", err)
	}
	fmt.Println("Change RAM Response:", string(changeRamResp))

	// Delete app
	deleteResp, err := app.Delete(appId)
	if err != nil {
		log.Fatalf("Error deleting app: %v", err)
	}
	fmt.Println("Delete Response:", string(deleteResp))
}

Team Examples

Team Management

package main

import (
	"fmt"
	"log"

	discloud "github.com/discloud/discloud-go/discloud"
)

func main() {
	token := "YOUR_API_TOKEN"
	client := discloud.Login(token)
	manager := discloud.TeamManager(client)

	appId := "YOUR_APP_ID"
	memberId := "MOD_USER_ID"

	// Get team members
	teamInfo, err := manager.GetTeam(appId)
	if err != nil {
		log.Fatalf("Error getting team: %v", err)
	}
	fmt.Printf("Team Members: %+v
", teamInfo)

	// Add member with permissions
	perms := []string{manager.Perms.StartApp, manager.Perms.All()[0]}
	addResp, err := manager.AddMember(appId, memberId, perms)
	if err != nil {
		log.Fatalf("Error adding member: %v", err)
	}
	fmt.Println("Add member response:", string(addResp))

	// Edit member permissions
	perms = []string{manager.Perms.LogsApp}
	editResp, err := manager.EditMember(appId, memberId, perms)
	if err != nil {
		log.Fatalf("Error editing permissions: %v", err)
	}
	fmt.Println("Edit permissions response:", string(editResp))

	// Remove team member
	removeResp, err := manager.RemoveMember(appId, memberId)
	if err != nil {
		log.Fatalf("Error removing member: %v", err)
	}
	fmt.Println("Remove member response:", string(removeResp))
}

Team Actions

package main

import (
	"fmt"
	"log"

	discloud "github.com/discloud/discloud-go/discloud"
)

func main() {
	token := "YOUR_API_TOKEN"
	client := discloud.Login(token)
	team := discloud.Team(client)

	appId := "YOUR_APP_ID"

	// Start team application
	startResp, err := team.Start(appId)
	if err != nil {
		log.Fatalf("Error starting app: %v", err)
	}
	fmt.Println("Start Response:", string(startResp))

	// Get team app status
	status, err := team.Status(appId)
	if err != nil {
		log.Fatalf("Error getting app status: %v", err)
	}
	fmt.Printf("App Status: %+v
", status)

	// Commit to team application
	commitResp, err := team.Commit(appId, "path/to/your/app.zip")
	if err != nil {
		log.Fatalf("Error committing: %v", err)
	}
	fmt.Println("Commit Response:", string(commitResp))
}

About

Go SDK πŸ’™

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages