api

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2025 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultBaseURL - base URL for PaperMC API
	DefaultBaseURL = "https://api.papermc.io"
	// DefaultTimeout - default timeout for HTTP requests
	DefaultTimeout = 30 * time.Second
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BuildResponse

type BuildResponse struct {
	ProjectID   string              `json:"project_id"`
	ProjectName string              `json:"project_name"`
	Version     string              `json:"version"`
	Build       int32               `json:"build"`
	Time        time.Time           `json:"time"`
	Channel     string              `json:"channel"`
	Promoted    bool                `json:"promoted"`
	Changes     []Change            `json:"changes"`
	Downloads   map[string]Download `json:"downloads"`
}

BuildResponse represents information about a specific build

type BuildsResponse

type BuildsResponse struct {
	ProjectID   string         `json:"project_id"`
	ProjectName string         `json:"project_name"`
	Version     string         `json:"version"`
	Builds      []VersionBuild `json:"builds"`
}

BuildsResponse represents a list of available builds for a project version

type Change

type Change struct {
	Commit  string `json:"commit"`
	Summary string `json:"summary"`
	Message string `json:"message"`
}

Change represents information about changes in a build

type Client

type Client struct {
	BaseURL    string
	HTTPClient *http.Client
	Limit      int // Limit the number of items to return (0 means no limit)
}

Client represents the PaperMC API client

func NewClient

func NewClient() *Client

NewClient creates a new instance of the PaperMC API client

func (*Client) DownloadBuild

func (c *Client) DownloadBuild(ctx context.Context, projectID, version string, build int32, download string) (io.ReadCloser, error)

DownloadBuild downloads the specified file from a build

func (*Client) DownloadFile

func (c *Client) DownloadFile(ctx context.Context, projectID, version string, build int32, downloadName, destPath string) (*DownloadResult, error)

DownloadFile downloads a file from a build and verifies its hash

func (*Client) DownloadLatestBuild

func (c *Client) DownloadLatestBuild(ctx context.Context, projectID, version, destDir string) (*DownloadResult, error)

DownloadLatestBuild downloads the latest build of the specified project version

func (*Client) DownloadLatestStableVersion

func (c *Client) DownloadLatestStableVersion(ctx context.Context, projectID, destDir string) (*DownloadResult, error)

DownloadLatestStableVersion downloads the latest stable version of the project

func (*Client) DownloadPromotedBuild

func (c *Client) DownloadPromotedBuild(ctx context.Context, projectID, version, destDir string) (*DownloadResult, error)

DownloadPromotedBuild downloads the recommended build of the specified version

func (*Client) FindPromotedBuild

func (c *Client) FindPromotedBuild(ctx context.Context, projectID, version string) (int32, error)

FindPromotedBuild finds a recommended (promoted) build for the specified version

func (*Client) FormatDownloadURL

func (c *Client) FormatDownloadURL(projectID, version string, build int32, downloadName string) string

FormatDownloadURL returns a URL for direct file download

func (*Client) GetBuild

func (c *Client) GetBuild(ctx context.Context, projectID, version string, build int32) (*BuildResponse, error)

GetBuild returns information about a specific build

func (*Client) GetBuildURL

func (c *Client) GetBuildURL(ctx context.Context, projectID, version string, build int32) (string, error)

GetBuildURL returns the download URL for a specific build

func (*Client) GetBuilds

func (c *Client) GetBuilds(ctx context.Context, projectID, version string) (*BuildsResponse, error)

GetBuilds returns a list of available builds for a project version

func (*Client) GetDefaultDownloadName

func (c *Client) GetDefaultDownloadName(ctx context.Context, projectID, version string, build int32) (string, error)

GetDefaultDownloadName returns the name of the main downloadable file for a build

func (*Client) GetLatestBuild

func (c *Client) GetLatestBuild(ctx context.Context, projectID, version string) (int32, error)

GetLatestBuild returns the number of the latest build for the specified version

func (*Client) GetLatestBuildURL

func (c *Client) GetLatestBuildURL(ctx context.Context, projectID, version string) (string, error)

GetLatestBuildURL returns the download URL for the latest build of a version

func (*Client) GetLatestVersion

func (c *Client) GetLatestVersion(ctx context.Context, projectID string) (string, error)

GetLatestVersion returns the latest available version for a project

func (*Client) GetLatestVersionURL

func (c *Client) GetLatestVersionURL(ctx context.Context, projectID string) (string, error)

GetLatestVersionURL returns the download URL for the latest version of a project

func (*Client) GetProject

func (c *Client) GetProject(ctx context.Context, projectID string) (*ProjectResponse, error)

GetProject returns information about a specific project

func (*Client) GetProjects

func (c *Client) GetProjects(ctx context.Context) (*ProjectsResponse, error)

GetProjects returns a list of all available projects

func (*Client) GetPromotedBuildURL

func (c *Client) GetPromotedBuildURL(ctx context.Context, projectID, version string) (string, error)

GetPromotedBuildURL returns the download URL for the promoted build of a version

func (*Client) GetRecommendedVersion

func (c *Client) GetRecommendedVersion(ctx context.Context, projectID string) (string, error)

GetRecommendedVersion returns the recommended version for the project Usually it's the latest stable (not SNAPSHOT and not pre) version

func (*Client) GetVersion

func (c *Client) GetVersion(ctx context.Context, projectID, version string) (*VersionResponse, error)

GetVersion returns information about a project version

func (*Client) GetVersionGroup

func (c *Client) GetVersionGroup(ctx context.Context, projectID, family string) (*VersionFamilyResponse, error)

GetVersionGroup returns information about a project's version group

func (*Client) GetVersionGroupBuilds

func (c *Client) GetVersionGroupBuilds(ctx context.Context, projectID, family string) (*VersionFamilyBuildsResponse, error)

GetVersionGroupBuilds returns a list of available builds for a version group

func (*Client) WithBaseURL

func (c *Client) WithBaseURL(baseURL string) *Client

WithBaseURL sets a custom base URL for the API

func (*Client) WithLimit

func (c *Client) WithLimit(limit int) *Client

WithLimit sets a limit for the number of items to return

func (*Client) WithTimeout

func (c *Client) WithTimeout(timeout time.Duration) *Client

WithTimeout sets a timeout for the HTTP client

type Download

type Download struct {
	Name   string `json:"name"`
	SHA256 string `json:"sha256"`
}

Download represents information about a downloadable file

type DownloadResult

type DownloadResult struct {
	Filename       string
	ExpectedSHA256 string
	ActualSHA256   string
	Valid          bool
}

DownloadResult contains the result of downloading a file

type ProjectResponse

type ProjectResponse struct {
	ProjectID     string   `json:"project_id"`
	ProjectName   string   `json:"project_name"`
	VersionGroups []string `json:"version_groups"`
	Versions      []string `json:"versions"`
}

ProjectResponse represents information about a project

type ProjectsResponse

type ProjectsResponse struct {
	Projects []string `json:"projects"`
}

ProjectsResponse represents a list of all available projects

type VersionBuild

type VersionBuild struct {
	Build     int32               `json:"build"`
	Time      time.Time           `json:"time"`
	Channel   string              `json:"channel"`
	Promoted  bool                `json:"promoted"`
	Changes   []Change            `json:"changes"`
	Downloads map[string]Download `json:"downloads"`
}

VersionBuild represents information about a build in the version context

type VersionFamilyBuild

type VersionFamilyBuild struct {
	Version   string              `json:"version"`
	Build     int32               `json:"build"`
	Time      time.Time           `json:"time"`
	Channel   string              `json:"channel"`
	Promoted  bool                `json:"promoted"`
	Changes   []Change            `json:"changes"`
	Downloads map[string]Download `json:"downloads"`
}

VersionFamilyBuild represents information about a build in the version group context

type VersionFamilyBuildsResponse

type VersionFamilyBuildsResponse struct {
	ProjectID    string               `json:"project_id"`
	ProjectName  string               `json:"project_name"`
	VersionGroup string               `json:"version_group"`
	Versions     []string             `json:"versions"`
	Builds       []VersionFamilyBuild `json:"builds"`
}

VersionFamilyBuildsResponse represents a list of available builds for a version group

type VersionFamilyResponse

type VersionFamilyResponse struct {
	ProjectID    string   `json:"project_id"`
	ProjectName  string   `json:"project_name"`
	VersionGroup string   `json:"version_group"`
	Versions     []string `json:"versions"`
}

VersionFamilyResponse represents information about a project's version group

type VersionResponse

type VersionResponse struct {
	ProjectID   string  `json:"project_id"`
	ProjectName string  `json:"project_name"`
	Version     string  `json:"version"`
	Builds      []int32 `json:"builds"`
}

VersionResponse represents information about a version

Jump to

Keyboard shortcuts

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