api

package
v0.1.0-beta Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2025 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Copyright (c) 2025 Nexlayer. All rights reserved.n// Use of this source code is governed by an MIT-stylen// license that can be found in the LICENSE file.nn

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIClient

type APIClient interface {
	// StartDeployment starts a new deployment using a YAML configuration file.
	// The YAML file should be provided as binary data using the 'text/x-yaml' content type.
	// Endpoint: POST /startUserDeployment/{applicationID?}
	StartDeployment(ctx context.Context, appID string, configPath string) (*APIResponse[DeploymentResponse], error)

	// StartDeploymentRaw starts a new deployment using raw YAML data without any parsing.
	// Endpoint: POST /startUserDeployment/{applicationID?}
	StartDeploymentRaw(ctx context.Context, appID string, yamlData []byte) (*APIResponse[DeploymentResponse], error)

	// SendFeedback submits feedback to Nexlayer regarding deployment or application experience.
	// Endpoint: POST /feedback
	SendFeedback(ctx context.Context, text string) error

	// SaveCustomDomain associates a custom domain with a specific application deployment.
	// Endpoint: POST /saveCustomDomain/{applicationID}
	SaveCustomDomain(ctx context.Context, appID string, domain string) (*APIResponse[DomainResponse], error)

	// GetDeployments retrieves all deployments for a specific application.
	// Endpoint: GET /getDeployments/{applicationID}
	GetDeployments(ctx context.Context, appID string) (*APIResponse[[]Deployment], error)

	// GetDeploymentInfo retrieves detailed information about a specific deployment.
	// Endpoint: GET /getDeploymentInfo/{namespace}/{applicationID}
	GetDeploymentInfo(ctx context.Context, namespace string, appID string) (*APIResponse[Deployment], error)

	// GetLogs retrieves logs for a specific deployment.
	// If follow is true, streams logs in real-time.
	// tail specifies the number of lines to return from the end of the logs.
	// Endpoint: GET /getDeploymentLogs/{namespace}
	GetLogs(ctx context.Context, namespace string, appID string, follow bool, tail int) ([]string, error)
}

type APIClientForCommands

type APIClientForCommands interface {
	GetDeploymentInfo(ctx context.Context, namespace string, appID string) (*APIResponse[Deployment], error)
	GetDeployments(ctx context.Context, appID string) (*APIResponse[[]Deployment], error)
	SaveCustomDomain(ctx context.Context, appID string, domain string) (*APIResponse[DomainResponse], error)
}

APIClientForCommands interface is used for API client operations used in commands.

type APIError

type APIError struct {
	StatusCode int    `json:"statusCode"`
	Message    string `json:"message"`
	ErrorCode  string `json:"error"`
}

APIError represents an error returned by the API

func (*APIError) Error

func (e *APIError) Error() string

Error implements the error interface

type APIResponse

type APIResponse[T any] struct {
	Message string `json:"message"`
	Data    T      `json:"data"`
}

APIResponse is a generic response type for all API responses

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client represents an API client for interacting with the Nexlayer API. The Nexlayer API enables rapid deployment of full-stack AI-powered applications by providing a simple template-based interface that abstracts away deployment complexity.

func NewClient

func NewClient(baseURL string) *Client

func (*Client) GetDeploymentInfo

func (c *Client) GetDeploymentInfo(ctx context.Context, namespace string, appID string) (*APIResponse[Deployment], error)

GetDeploymentInfo retrieves detailed information about a specific deployment. Endpoint: GET /getDeploymentInfo/{namespace}/{applicationID}

func (*Client) GetDeployments

func (c *Client) GetDeployments(ctx context.Context, appID string) (*APIResponse[[]Deployment], error)

GetDeployments retrieves all deployments for a specific application. Endpoint: GET /getDeployments/{applicationID}

func (*Client) GetLogs

func (c *Client) GetLogs(ctx context.Context, namespace string, appID string, follow bool, tail int) ([]string, error)

GetLogs retrieves logs for a specific deployment

func (*Client) ListDeployments

func (c *Client) ListDeployments(ctx context.Context) (*APIResponse[[]Deployment], error)

NewClient creates a new Nexlayer API client. If baseURL is empty, defaults to the staging environment at app.staging.nexlayer.io. ListDeployments retrieves all deployments. Endpoint: GET /listDeployments

func (*Client) SaveCustomDomain

func (c *Client) SaveCustomDomain(ctx context.Context, appID string, domain string) (*APIResponse[DomainResponse], error)

SaveCustomDomain associates a custom domain with a specific application deployment. Endpoint: POST /saveCustomDomain/{applicationID}

func (*Client) SendFeedback

func (c *Client) SendFeedback(ctx context.Context, text string) error

SendFeedback submits feedback to Nexlayer. Endpoint: POST /feedback

func (*Client) SetToken

func (c *Client) SetToken(token string)

SetToken sets the authentication token for the client

func (*Client) StartDeployment

func (c *Client) StartDeployment(ctx context.Context, appID string, yamlFile string) (*APIResponse[DeploymentResponse], error)

StartDeployment starts a new deployment using a YAML configuration file. The applicationID parameter is optional as per the OpenAPI spec (/startUserDeployment/{applicationID?}). If applicationID is empty, the deployment will be created without an associated application. Endpoint: POST /startUserDeployment/{applicationID?}

func (*Client) StartDeploymentRaw

func (c *Client) StartDeploymentRaw(ctx context.Context, appID string, yamlData []byte) (*APIResponse[DeploymentResponse], error)

StartDeploymentRaw starts a new deployment using raw YAML data without any parsing. Endpoint: POST /startUserDeployment/{applicationID?}

type ClientAPI

type ClientAPI interface {
	StartDeployment(ctx context.Context, appID string, configPath string) (*APIResponse[DeploymentResponse], error)
	SendFeedback(ctx context.Context, text string) error
	SaveCustomDomain(ctx context.Context, appID string, domain string) (*APIResponse[DomainResponse], error)
	GetDeployments(ctx context.Context, appID string) (*APIResponse[[]Deployment], error)
	GetDeploymentInfo(ctx context.Context, namespace string, appID string) (*APIResponse[Deployment], error)
	GetLogs(ctx context.Context, namespace string, appID string, follow bool, tail int) ([]string, error)
}

ClientAPI is an interface that abstracts the methods required for API interactions.

type Deployment

type Deployment struct {
	Namespace    string      `json:"namespace"`
	TemplateID   string      `json:"templateID"`
	TemplateName string      `json:"templateName"`
	Status       string      `json:"deploymentStatus"`
	URL          string      `json:"url,omitempty"`
	CustomDomain string      `json:"customDomain,omitempty"`
	Version      string      `json:"version,omitempty"`
	CreatedAt    time.Time   `json:"createdAt,omitempty"`
	LastUpdated  time.Time   `json:"lastUpdated,omitempty"`
	PodStatuses  []PodStatus `json:"podStatuses,omitempty"`
}

Deployment represents a deployment in the system Matches getDeploymentInfoResponse in OpenAPI spec

type DeploymentResponse

type DeploymentResponse struct {
	Message   string `json:"message"`
	Namespace string `json:"namespace"`
	URL       string `json:"url"`
}

DeploymentResponse represents the response from starting a deployment Matches startUserDeploymentResponse in OpenAPI spec

type Domain

type Domain struct {
	Domain        string    `json:"domain"`
	ApplicationID string    `json:"applicationId"`
	Status        string    `json:"status"`
	CreatedAt     time.Time `json:"createdAt"`
	SSLEnabled    bool      `json:"sslEnabled"`
}

Domain represents a custom domain configuration

type DomainResponse

type DomainResponse struct {
	Message string `json:"message"`
}

DomainResponse represents the response from saving a custom domain Matches saveCustomDomainResponse in OpenAPI spec

type Feedback

type Feedback struct {
	Text string `json:"text"`
}

Feedback represents the feedback request body

type MockServer

type MockServer struct {
	// contains filtered or unexported fields
}

func NewMockServer

func NewMockServer() *MockServer

func (*MockServer) Close

func (s *MockServer) Close()

func (*MockServer) URL

func (s *MockServer) URL() string

type PodStatus

type PodStatus struct {
	Name      string    `json:"name"`
	Type      string    `json:"type"`
	Status    string    `json:"status"`
	Ready     bool      `json:"ready"`
	Restarts  int       `json:"restarts"`
	Image     string    `json:"image"`
	CreatedAt time.Time `json:"createdAt"`
}

PodStatus represents the status of a pod in a deployment

Directories

Path Synopsis
Package testing provides test utilities for the Nexlayer API client
Package testing provides test utilities for the Nexlayer API client

Jump to

Keyboard shortcuts

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