indexnow

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2023 License: MIT Imports: 10 Imported by: 4

README

easyindex for Google indexing API

Required

Install

go get github.com/usk81/easyindex

Example

Publish API
package main

import (
	"context"
	"fmt"

	"github.com/usk81/easyindex/indexnow"
	"github.com/usk81/easyindex/logger"
)

func main() {
	l, err := logger.New("debug")
	if err != nil {
		panic(err)
	}

	us := []string{
		"https://example.com/foo",
		"https://example.com/bar",
	}

	submit, err := indexnow.Submit(indexnow.Config{
		SearchEngineBaseURL: indexnow.Bing,
		Logger:              l,
		Logging:             true,
	})
	if err != nil {
		panic(err)
	}

	ctx := context.Background()
	us, skips := submit.Precheck(ctx, us)

	// ref. https://www.indexnow.org/documentation
	err = submit.Execute(indexnow.SubmitInput{
		Context:     ctx,
		Host:        "https://example.com",
		Key:         "5d87a32cd39c4162bbd580ffaa6b511f",
		KeyLocation: "https://example.com/5d87a32cd39c4162bbd580ffaa6b511f.txt",
		URLList:     us,
	})
	if err != nil {
		panic(err)
	}
	fmt.Printf("requests: %#v\n", us)
	fmt.Printf("skipRequests: %#v\n", skips)
}

Documentation

Index

Constants

View Source
const (
	Bing   = "https://www.bing.com"
	Seznam = "https://seznam.cz"
	Yandex = "https://yandex.com"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// SearchEngineBaseURL
	//   e.g. https://www.bing.com
	SearchEngineBaseURL string

	// client
	Client *http.Client

	// Logger is logger instance
	Logger *zap.Logger

	// Logging is the flag if outputs logs
	Logging bool

	// Quota is Publish API requests limit per day
	Quota *int
}

type SkipedPublishRequest

type SkipedPublishRequest struct {
	URL    string
	Reason error
}

type SubmitInput

type SubmitInput struct {
	Context     context.Context
	Host        string
	Key         string
	KeyLocation string
	URLList     []string
}

type Submitter

type Submitter interface {
	Precheck(ctx context.Context, input []string) (requests []string, skips []SkipedPublishRequest)
	Execute(input SubmitInput) (err error)
}

Submitter ...

func MustSubmit

func MustSubmit(conf Config) Submitter

func Submit

func Submit(conf Config) (Submitter, error)

Jump to

Keyboard shortcuts

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