1.3 KB
site.go
package models

import (
	"time"

	"github.com/readysite/readysite/pkg/database"
)

// Site represents a hosted ReadySite instance.
// The ID is a URL-safe slug derived from the name (e.g. "my-portfolio").
type Site struct {
	database.Model
	UserID               string
	Name                 string
	Plan                 string    // "free" / "hobby" / "pro"
	Status               string    // "launching" / "active" / "failed" / "sleeping" / "stopped" / "deleted" / "shutdown"
	Description          string
	AuthSecret           string    // JWT signing secret shared with the site's website container
	LastActiveAt         time.Time // Tracks when site last received traffic
	StripeSubscriptionID string
	StripePriceID        string
}

// IsPro returns true if this site is on the Pro plan.
func (s *Site) IsPro() bool { return s.Plan == "pro" }

// IsHobby returns true if this site is on the Hobby plan.
func (s *Site) IsHobby() bool { return s.Plan == "hobby" }

// IsFree returns true if this site is on the Free plan.
func (s *Site) IsFree() bool { return s.Plan == "free" }

// Subdomain returns the default subdomain for this site (the slug ID).
func (s *Site) Subdomain() string {
	return s.ID
}

// Owner returns the user who owns this site.
func (s *Site) Owner() (*User, error) {
	return Users.Get(s.UserID)
}
← Back