provider

package
v1.5.1 Latest Latest
Warning

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

Go to latest
Published: May 10, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidURL = errors.New("invalid provider url")
View Source
var ErrNotFound = errors.New("provider not found")
View Source
var ErrRefreshIntervalTooShort = errors.New("refresh interval must be at least 5 minutes")
View Source
var ErrSubscriptionProviderRef = errors.New("provider is referenced by a subscription")

Functions

This section is empty.

Types

type CreateProviderInput

type CreateProviderInput struct {
	Name                   string `json:"name"`
	URL                    string `json:"url"`
	RefreshIntervalMinutes int64  `json:"refresh_interval_minutes"`
	Abbrev                 string `json:"abbrev"`
}

type Handler

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

func NewHandler

func NewHandler(service *Service) *Handler

func (*Handler) RegisterRoutes

func (h *Handler) RegisterRoutes(mux *http.ServeMux)

func (*Handler) SetRefresher

func (h *Handler) SetRefresher(f RefreshProviderFunc)

type Provider

type Provider struct {
	ID                     int64     `json:"id"`
	Name                   string    `json:"name"`
	URL                    string    `json:"url"`
	RefreshIntervalMinutes int64     `json:"refresh_interval_minutes"`
	Abbrev                 string    `json:"abbrev"`
	Used                   int64     `json:"used"`
	Total                  int64     `json:"total"`
	Expire                 int64     `json:"expire"`
	CreatedAt              time.Time `json:"created_at"`
	UpdatedAt              time.Time `json:"updated_at"`
	LastRefreshStatus      string    `json:"last_refresh_status,omitempty"`
	LastRefreshMessage     string    `json:"last_refresh_message,omitempty"`
	LastAttemptedAt        time.Time `json:"last_attempted_at"`
}

type ProxyNode

type ProxyNode struct {
	ID         int64  `json:"id"`
	ProviderID int64  `json:"provider_id"`
	Name       string `json:"name"`
	RawYAML    string `json:"raw_yaml"`
	UpdateMark int64  `json:"update_mark"`
	Enabled    bool   `json:"enabled"`
}

type RefreshAttempt

type RefreshAttempt struct {
	ID          int64
	ProviderID  int64
	Status      string
	Message     string
	AttemptedAt time.Time
}

type RefreshFailedError

type RefreshFailedError struct {
	Message string
}

func (*RefreshFailedError) Error

func (e *RefreshFailedError) Error() string

type RefreshProviderFunc

type RefreshProviderFunc func(ctx context.Context, providerID int64) error

type ReplaceSnapshotInput

type ReplaceSnapshotInput struct {
	Format       string
	Nodes        []map[string]any
	Used         int64
	Total        int64
	Expire       int64
	HasUsageInfo bool
}

type Repository

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

func NewRepository

func NewRepository(db *sql.DB) *Repository

func (*Repository) Create

func (r *Repository) Create(ctx context.Context, p Provider) (Provider, error)

func (*Repository) Delete

func (r *Repository) Delete(ctx context.Context, id int64) error

func (*Repository) GetByID

func (r *Repository) GetByID(ctx context.Context, id int64) (Provider, error)

func (*Repository) GetLatestSnapshot

func (r *Repository) GetLatestSnapshot(ctx context.Context, providerID int64) (Snapshot, error)

func (*Repository) List

func (r *Repository) List(ctx context.Context) ([]Provider, error)

func (*Repository) ListLatestNodes

func (r *Repository) ListLatestNodes(ctx context.Context) ([]map[string]any, error)

func (*Repository) ListLatestNodesByProviders

func (r *Repository) ListLatestNodesByProviders(ctx context.Context, providerIDs []int64) ([]map[string]any, error)

func (*Repository) ListProxyNodesByProvider

func (r *Repository) ListProxyNodesByProvider(ctx context.Context, providerID int64) ([]ProxyNode, error)

func (*Repository) RecordRefreshFailure

func (r *Repository) RecordRefreshFailure(ctx context.Context, providerID int64, message string) error

func (*Repository) ReplaceLastKnownGoodSnapshot

func (r *Repository) ReplaceLastKnownGoodSnapshot(ctx context.Context, providerID int64, in ReplaceSnapshotInput) error

func (*Repository) ToggleNodeEnabled

func (r *Repository) ToggleNodeEnabled(ctx context.Context, nodeID int64) (bool, error)

func (*Repository) Update

func (r *Repository) Update(ctx context.Context, p Provider) (Provider, error)

type Service

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

func NewService

func NewService(repo *Repository) *Service

func (*Service) Create

func (s *Service) Create(ctx context.Context, in CreateProviderInput) (Provider, error)

func (*Service) Delete

func (s *Service) Delete(ctx context.Context, id int64) error

func (*Service) GetByID

func (s *Service) GetByID(ctx context.Context, id int64) (Provider, error)

func (*Service) GetLatestSnapshot

func (s *Service) GetLatestSnapshot(ctx context.Context, id int64) (Snapshot, error)

func (*Service) List

func (s *Service) List(ctx context.Context) ([]Provider, error)

func (*Service) ListNodes

func (s *Service) ListNodes(ctx context.Context, providerID int64) ([]ProxyNode, error)

func (*Service) SetSubscriptionReferenceChecker

func (s *Service) SetSubscriptionReferenceChecker(checker SubscriptionReferenceChecker)

func (*Service) ToggleNodeEnabled

func (s *Service) ToggleNodeEnabled(ctx context.Context, nodeID int64) (bool, error)

func (*Service) Update

func (s *Service) Update(ctx context.Context, id int64, in UpdateProviderInput) (Provider, error)

type Snapshot

type Snapshot struct {
	ID             int64     `json:"id"`
	ProviderID     int64     `json:"provider_id"`
	Format         string    `json:"format"`
	NormalizedYAML string    `json:"normalized_yaml"`
	NodeCount      int       `json:"node_count"`
	FetchedAt      time.Time `json:"fetched_at"`
}

type SubscriptionReferenceChecker

type SubscriptionReferenceChecker func(ctx context.Context, providerID int64) (bool, error)

type UpdateProviderInput

type UpdateProviderInput struct {
	Name                   string `json:"name"`
	URL                    string `json:"url"`
	RefreshIntervalMinutes int64  `json:"refresh_interval_minutes"`
	Abbrev                 string `json:"abbrev"`
}

Jump to

Keyboard shortcuts

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