indexnowru

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2026 License: MIT Imports: 11 Imported by: 0

README

Index-Now.ru Go SDK

Официальный Go-клиент для REST API Index-Now.ru. SDK отправляет URL, получает статусы и статистику, управляет sitemap и запускает облачные аудиты. Runtime-зависимостей нет.

Отправка URL ускоряет обнаружение страниц поисковыми системами, но не гарантирует включение страницы в индекс.

Установка

go get github.com/arseniigruzdev/index-now-ru-go

Быстрый старт

package main

import (
	"context"
	"fmt"
	"os"

	indexnowru "github.com/arseniigruzdev/index-now-ru-go"
)

func main() {
	client, err := indexnowru.NewClient(os.Getenv("INDEX_NOW_RU_API_TOKEN"))
	if err != nil {
		panic(err)
	}

	sites, err := client.ListSites(context.Background(), "")
	if err != nil {
		panic(err)
	}
	siteID := sites[0]["id"].(string)

	result, err := client.Submit(context.Background(), indexnowru.SubmissionRequest{
		SiteID: siteID,
		URLs:   []string{"https://example.com/new-page"},
	})
	if err != nil {
		panic(err)
	}
	fmt.Println(result)
}

По умолчанию используются каналы indexnow_org, indexnow_bing и ping, режим отправки — normal. Токен передаётся только в заголовке Authorization: Bearer …. HTTP-редиректы намеренно не выполняются.

Методы

  • GetAccount, ListProjects, ListSites;
  • Submit, GetStatus, GetHistory, GetDashboard;
  • ListSitemaps, CheckSitemap;
  • PageAudit, StartCrawlAudit, GetCrawlAudit.

Разработка

go test ./...
go vet ./...

Ссылки

License

MIT © Index-Now.ru.

Documentation

Overview

Package indexnowru provides a dependency-free client for the Index-Now.ru API.

Index

Constants

View Source
const (
	DefaultBaseURL = "https://index-now.ru/api/v1"
)

Variables

View Source
var (
	// ErrTransport identifies DNS, TLS, timeout and other HTTP transport failures.
	ErrTransport = errors.New("index-now.ru transport error")
	// ErrInvalidResponse identifies malformed or oversized API responses.
	ErrInvalidResponse = errors.New("index-now.ru invalid response")
)

Functions

This section is empty.

Types

type APIError

type APIError struct {
	StatusCode int
	Message    string
	RequestID  string
	RetryAfter *float64
	Body       Object
}

APIError represents a non-success response from Index-Now.ru.

func (*APIError) Error

func (errorValue *APIError) Error() string

type Client

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

Client is safe for concurrent use.

func NewClient

func NewClient(apiToken string, options ...Option) (*Client, error)

NewClient creates an authenticated Index-Now.ru API client.

func (*Client) CheckSitemap

func (client *Client) CheckSitemap(ctx context.Context, sitemapID string) (Object, error)

CheckSitemap queues an immediate sitemap check.

func (*Client) GetAccount

func (client *Client) GetAccount(ctx context.Context) (Object, error)

GetAccount returns subscription limits and API capabilities.

func (*Client) GetCrawlAudit

func (client *Client) GetCrawlAudit(ctx context.Context, siteID string) (Object, error)

GetCrawlAudit returns the current or most recent crawl audit.

func (*Client) GetDashboard

func (client *Client) GetDashboard(ctx context.Context, siteID string) (Object, error)

GetDashboard returns compact monthly site statistics.

func (*Client) GetHistory

func (client *Client) GetHistory(ctx context.Context, siteID string, limit int) (Object, error)

GetHistory returns the newest submission records.

func (*Client) GetStatus

func (client *Client) GetStatus(ctx context.Context, submissionID string) (Object, error)

GetStatus returns one submission with per-engine statuses.

func (*Client) ListProjects

func (client *Client) ListProjects(ctx context.Context) ([]Object, error)

ListProjects returns projects with their nested sites.

func (*Client) ListSitemaps

func (client *Client) ListSitemaps(ctx context.Context) ([]Object, error)

ListSitemaps returns sitemap watchers for the token's organization.

func (*Client) ListSites

func (client *Client) ListSites(ctx context.Context, projectID string) ([]Object, error)

ListSites returns sites, optionally limited to one project.

func (*Client) PageAudit

func (client *Client) PageAudit(ctx context.Context, pageURL string) (Object, error)

PageAudit runs the cloud page-audit tool.

func (*Client) StartCrawlAudit

func (client *Client) StartCrawlAudit(
	ctx context.Context,
	siteID string,
	request CrawlAuditRequest,
) (Object, error)

StartCrawlAudit starts an asynchronous crawl audit.

func (*Client) Submit

func (client *Client) Submit(ctx context.Context, request SubmissionRequest) (Object, error)

Submit sends between 1 and 100 URLs for indexing.

type CrawlAuditRequest

type CrawlAuditRequest struct {
	MaxDepth            int      `json:"maxDepth"`
	IncludePatterns     []string `json:"includePatterns,omitempty"`
	ExcludePatterns     []string `json:"excludePatterns,omitempty"`
	UseJinaFallback     bool     `json:"useJinaFallback"`
	RespectRobots       bool     `json:"respectRobots"`
	RespectNofollow     bool     `json:"respectNofollow"`
	KeepQueryParameters bool     `json:"keepQueryParameters"`
}

CrawlAuditRequest configures a site crawl.

type Object

type Object map[string]any

Object represents a JSON object returned by the API. The public API evolves additively, so unknown fields are preserved.

type Option

type Option func(*clientOptions) error

Option configures a Client.

func WithBaseURL

func WithBaseURL(rawURL string) Option

WithBaseURL overrides the production API URL. It is intended for compatible test servers.

func WithHTTPClient

func WithHTTPClient(client *http.Client) Option

WithHTTPClient supplies an HTTP client. Redirects remain disabled so the bearer token cannot cross origins.

func WithTimeout

func WithTimeout(timeout time.Duration) Option

WithTimeout changes the default 30-second request timeout.

func WithUserAgent

func WithUserAgent(userAgent string) Option

WithUserAgent overrides the SDK User-Agent.

type SubmissionRequest

type SubmissionRequest struct {
	SiteID         string   `json:"siteId"`
	URLs           []string `json:"urls"`
	Engines        []string `json:"engines,omitempty"`
	SubmissionMode string   `json:"submissionMode,omitempty"`
}

SubmissionRequest describes one URL-submission request.

Jump to

Keyboard shortcuts

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