indexing

package
v0.0.0-...-bf55f72 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package indexing provides a developer friendly module to Google's Indexing API

More info about the API: https://developers.google.com/search/apis/indexing-api/v3/quickstart

Index

Constants

View Source
const (
	OauthScope          = "https://www.googleapis.com/auth/indexing"                     // AuthorizationScope is required for the Indexing API
	GetMetadataEndpoint = "https://indexing.googleapis.com/v3/urlNotifications/metadata" // getMetadata endpoint
	PublishEndpoint     = "https://indexing.googleapis.com/v3/urlNotifications:publish"  // publish endpoint

)
View Source
const (
	PublishTypeUpdate = "URL_UPDATED"
	PublishTypeDelete = "URL_DELETED"
)

Variables

This section is empty.

Functions

func CreateDeleteRequest

func CreateDeleteRequest(u string) *strings.Reader

CreateDeleteRequest returns an io.Reader for the request body with "URL_DELETED".

func CreateUpdateRequest

func CreateUpdateRequest(u string) *strings.Reader

CreateUpdateRequest returns an io.Reader for the request body with "URL_UPDATED".

Types

type Client

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

func NewClientFromJSON

func NewClientFromJSON(jsonKey []byte) (*Client, error)

NewClientFromJSON creates Client from Google Developers service account JSON key file.

func NewClientFromJSONFile

func NewClientFromJSONFile(name string) (*Client, error)

NewClientFromJSONFile reads file in path name and creates Client from Google Developers service account JSON key file.

func (*Client) Delete

func (c *Client) Delete(u string) error

Delete notifies Google that the given URL can be removed Google's index.

See more: https://developers.google.com/search/apis/indexing-api/v3/using-api#removing

func (*Client) Get

Get returns the last time Google received each kind of notification for a given URL.

This function sets the Oauth2 scope to OauthScope.

If the given URL is not indexed, returns error git.gorbe.io/go/google/errors.ErrNotFound

For more: https://developers.google.com/search/apis/indexing-api/v3/using-api#gettinginfo

func (*Client) IsIndexed

func (c *Client) IsIndexed(u string) (bool, error)

IsINdexed returns whether the given URL u is indexed.

- If the returned error is git.gorbe.io/go/google/errors.ErrNotFound, than reports `false` (the error will be `nil`!) - if the `latestUpdate` field is not set, returns `false` - If the `latestRemove` field is not set, but the `latestUpdate` is set, returns `true` - If the latest UPDATE request was after the latest DELETE request

Only the git.gorbe.io/go/google/errors.ErrNotFound is not returned.

func (*Client) Update

func (c *Client) Update(u string) error

Update notifies Google of a new URL to crawl or that content at a previously-submitted URL has been updated.

See more: https://developers.google.com/search/apis/indexing-api/v3/using-api#url

type UrlNotification

type UrlNotification struct {
	Url        string    `json:"url"`
	Type       string    `json:"type"`
	NotifyTime time.Time `json:"notifyTime,omitempty"`
}

type UrlNotificationMetadata

type UrlNotificationMetadata struct {
	Url          string           `json:"url"`
	LatestUpdate *UrlNotification `json:"latestUpdate"`
	LatestRemove *UrlNotification `json:"latestRemove"`
}

func ParseUrlNotificationMetadata

func ParseUrlNotificationMetadata(data []byte) (*UrlNotificationMetadata, error)

func ReadUrlNotificationMetadata

func ReadUrlNotificationMetadata(r io.Reader) (*UrlNotificationMetadata, error)

Jump to

Keyboard shortcuts

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