site

package
v1.8.2 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: MIT Imports: 25 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package site resolves the website a command acts on and remembers it per directory, like `vercel link`.

Index

Constants

View Source
const (
	Dir = ".hostinger"
	// File is shared with the deploy-to-hosting skill, so Save keeps its fields.
	File = "site.json"
)

Variables

View Source
var Client = func() *api.RawClient { return api.Raw() }

Tests replace Client.

View Source
var ErrNoBuild error = &utils.FlagError{Err: errors.New("no build given: pass the build UUID")}
View Source
var ErrNoDomain error = &utils.FlagError{Err: errors.New("no domain given: pass the domain or --domain")}
View Source
var ErrNoOrder error = &utils.FlagError{Err: errors.New("no order given: pass the order ID")}
View Source
var ErrNoUsername error = &utils.FlagError{Err: errors.New("no hosting account given: pass the username, or run `hostinger link`")}
View Source
var ErrNoWebsite error = &utils.FlagError{Err: errors.New("no website given: pass the domain, or run `hostinger link`")}
View Source
var Interactive = func() bool {
	if viper.GetBool("no_input") || os.Getenv("HOSTINGER_MAIL_NONINTERACTIVE") != "" {
		return false
	}
	if ci := strings.ToLower(os.Getenv("CI")); ci != "" && ci != "false" && ci != "0" {
		return false
	}
	return term.IsTerminal(int(os.Stdin.Fd())) && term.IsTerminal(int(os.Stderr.Fd()))
}

Interactive also checks CI and HOSTINGER_MAIL_NONINTERACTIVE: agents and CI runners often have a pseudo-terminal. Tests replace it.

View Source
var Spin = func(msg string) func(done string) {
	if !Interactive() {
		return func(string) {}
	}
	sp, err := pterm.DefaultSpinner.WithWriter(os.Stderr).Start(msg)
	if err != nil {
		return func(string) {}
	}
	return func(done string) { sp.Success(done) }
}

Spin shows a spinner on stderr in a terminal; call the result to end it. Tests replace it.

Functions

func CommittedLink(dir string) string

CommittedLink returns the link file in dir that Load reads when Git tracks it, else "". A cloned repository can ship one naming someone else's website, so a committed link is not consent to replace it. A repository that cannot be read counts as tracking it.

func DefaultDomain

func DefaultDomain(cmd *cobra.Command) (string, error)

DefaultDomain is the website named by flags, env, link or config, not args. A link that cannot be read is an error only when it is consulted.

func HostingPlanNames

func HostingPlanNames(ctx context.Context, c *api.RawClient) (map[int]string, error)

func Label

func Label(w Website) string

func LinkDirs

func LinkDirs(start string) ([]string, error)

LinkDirs are where a link for start can live: start, then its parents up to the repository root. It never climbs into the home directory or above, so a link made there once does not apply to every project below it.

func NormalizeDomain

func NormalizeDomain(s string) string

NormalizeDomain turns a pasted URL into a domain (no scheme, path, port, trailing dot or www.).

func Path

func Path(dir string) string

func PlanLabels

func PlanLabels(sites []Website, names map[int]string) map[int]string

PlanLabels are a grouped picker's labels: unknown orders read "Order N", same-named plans get their order id, and one plan gives nil (a flat picker).

func PlanNames

func PlanNames(orders []HostingOrder) map[int]string

func PlanOption

func PlanOption(w Website, labels map[int]string) string

func Portfolio

func Portfolio(ctx context.Context) ([]string, error)

func Remove added in v1.7.1

func Remove(dir string) error

Remove deletes the link files only: Dir can also hold other tools' files (the headless skill's workspaces under ~/.hostinger). Dir goes too once empty, unless it is a symlinked, shared folder.

func Resolve

func Resolve(cmd *cobra.Command, args []string, extras int) (username, domain string, rest []string, err error)

Resolve returns a site-scoped command's website and the remaining args. One arg is the domain; none means --domain, HOSTINGER_MAIL_DOMAIN, the link, default_domain, then a prompt.

func ResolveBuild

func ResolveBuild(cmd *cobra.Command, args []string, extras int) (username, domain, build string, rest []string, err error)

ResolveBuild is Resolve plus [build-uuid]: a UUID-shaped arg is the build; else the build up last started, else a prompt.

func ResolveDomain

func ResolveDomain(cmd *cobra.Command, args []string, extras int, group string) (domain string, rest []string, err error)

ResolveDomain: for hosting the domain is a website (see Resolve). For domains and DNS the link only counts when its domain is in the portfolio, since a free subdomain is not a zone.

func ResolveOrder

func ResolveOrder(cmd *cobra.Command, args []string, extras int, group string) (orderID string, rest []string, err error)

ResolveOrder: arg, else --order-id, HOSTINGER_MAIL_ORDER_ID, the link (hosting only), then a prompt.

func ResolveUsername

func ResolveUsername(cmd *cobra.Command, args []string, extras int) (username string, rest []string, err error)

ResolveUsername: arg, else --username, HOSTINGER_MAIL_USERNAME, the account of the default website, then a prompt.

func Save

func Save(dir string, p *Project) error

Save writes the link, keeping other tools' fields, and gitignores Dir since it names the hosting account.

func SelectHeight

func SelectHeight(options int) int

SelectHeight fits the list below the question, at least five rows.

func SortByPlan

func SortByPlan(sites []Website, labels map[int]string)

func Username

func Username(ctx context.Context, domain string) (string, error)

Username comes from the link when it names domain, else from the API.

Types

type BuildRef

type BuildRef struct {
	UUID  string    `json:"uuid"`
	State string    `json:"state,omitempty"`
	At    time.Time `json:"at"`
}

type Context added in v1.5.0

type Context struct {
	Domain         string   `json:"domain,omitempty"`
	DomainSource   string   `json:"domainSource"`
	Username       string   `json:"username,omitempty"`
	UsernameSource string   `json:"usernameSource,omitempty"`
	OrderID        string   `json:"orderId,omitempty"`
	OrderSource    string   `json:"orderSource,omitempty"`
	LinkFile       string   `json:"linkFile,omitempty"`
	Link           *Project `json:"link,omitempty"`
	ConfigFile     string   `json:"configFile,omitempty"`
}

Context is what `hostinger link --show` prints: each value and its source.

func Explain added in v1.5.0

func Explain(cmd *cobra.Command) (*Context, error)

Explain resolves like the generated commands, without prompting.

func (*Context) Lines added in v1.5.0

func (c *Context) Lines() []string

type HostingOrder

type HostingOrder struct {
	ID             int    `json:"id"`
	Status         string `json:"status"`
	SubscriptionID string `json:"subscription_id"`
	Plan           struct {
		Name string `json:"name"`
	} `json:"plan"`
	// DisplayName comes from the billing subscription, when known.
	DisplayName string `json:"-"`
}

func HostingOrders

func HostingOrders(ctx context.Context, c *api.RawClient) ([]HostingOrder, error)

HostingOrders names each order after its billing subscription, since the orders API only has the plan key.

func (HostingOrder) Label

func (o HostingOrder) Label() string

type NodeSettings

type NodeSettings struct {
	NodeVersion     int    `json:"nodeVersion,omitempty"`
	AppType         string `json:"appType,omitempty"`
	RootDirectory   string `json:"rootDirectory,omitempty"`
	OutputDirectory string `json:"outputDirectory,omitempty"`
	BuildScript     string `json:"buildScript,omitempty"`
	EntryFile       string `json:"entryFile,omitempty"`
	PackageManager  string `json:"packageManager,omitempty"`
}

NodeSettings are remembered build settings; empty strings mean "not set".

type Order

type Order struct {
	ID     string
	Label  string
	Status string
}

Order is any product's order, reduced to what a prompt needs.

func ChooseOrder

func ChooseOrder(ctx context.Context, group string) (*Order, error)

ChooseOrder returns the only usable order without asking.

func ListOrders

func ListOrders(ctx context.Context, c *api.RawClient, group string) ([]Order, error)

type Project

type Project struct {
	// Kind is "website"; empty in older files means the same.
	Kind string `json:"kind,omitempty"`
	// Path is the deployed folder relative to the link; empty is the directory itself.
	Path     string `json:"path,omitempty"`
	OrderID  int    `json:"orderId,omitempty"`
	Domain   string `json:"domain"`
	Username string `json:"username,omitempty"`
	Type     string `json:"type,omitempty"`
	// Headless is set for a headless website, which only takes Node.js deploys.
	Headless bool `json:"headless,omitempty"`
	// Source is "upload" or "git".
	Source string `json:"source,omitempty"`
	// Node is only written after a successful build.
	Node *NodeSettings `json:"node,omitempty"`
	// Build is the last build up started, so the build commands default to it.
	Build *BuildRef `json:"build,omitempty"`
}

func Find

func Find(start string) (*Project, string, error)

Find looks for a link in start and its parents, returning it and its directory.

func Load

func Load(dir string) (*Project, error)

Load returns nil, nil when dir has no link.

type Website

type Website struct {
	Domain      string `json:"domain"`
	Username    string `json:"username"`
	OrderID     int    `json:"order_id"`
	WebsiteType string `json:"website_type"`
	VhostType   string `json:"vhost_type"`
	IsEnabled   bool   `json:"is_enabled"`
}

func ChooseWebsite

func ChooseWebsite(ctx context.Context, current string) (*Website, error)

ChooseWebsite returns the only website without asking; current is preselected.

func FindWebsite

func FindWebsite(ctx context.Context, c *api.RawClient, domain string) (*Website, error)

func FindWebsiteWith

func FindWebsiteWith(ctx context.Context, list func(context.Context, string) ([]Website, error), domain string) (*Website, error)

func ListWebsites

func ListWebsites(ctx context.Context, domain string) ([]Website, error)

ListWebsites filters by domain as a substring; empty lists all.

func ListWebsitesWith

func ListWebsitesWith(ctx context.Context, c *api.RawClient, domain string) ([]Website, error)

func (Website) IsHeadless added in v1.7.0

func (w Website) IsHeadless() bool

IsHeadless reports a headless website: a Node.js frontend whose backend (WordPress, a store, PocketBase) lives in its own folder, such as /cms.

Jump to

Keyboard shortcuts

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