robots

package
v0.0.0-...-c5d5a31 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2020 License: Apache-2.0 Imports: 7 Imported by: 2

Documentation

Overview

Package robots handles caching robots.txt files

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cacher

type Cacher interface {
	IndexExists() (bool, error)
	Setup() error
	Put(*Robots)
	Get(host string) (*Robots, error)
}

Cacher handles the caching backend for robots.txt files

type ElasticSearch

type ElasticSearch struct {
	Client *elastic.Client
	Index  string
	Type   string
	Bulk   *elastic.BulkProcessor
}

ElasticSearch holds our Elasticsearch connection and index information

func (*ElasticSearch) Get

func (e *ElasticSearch) Get(sh string) (*Robots, error)

Get retrieves a single cached robots.txt file

func (*ElasticSearch) IndexExists

func (e *ElasticSearch) IndexExists() (bool, error)

IndexExists returns true if the index exists

func (*ElasticSearch) Mapping

func (e *ElasticSearch) Mapping() string

Mapping is the mapping of our robots Index

func (*ElasticSearch) Put

func (e *ElasticSearch) Put(r *Robots)

Put caches a robots.txt file

func (*ElasticSearch) Setup

func (e *ElasticSearch) Setup() error

Setup creates an index for caching robots.txt files

type Robots

type Robots struct {
	SchemeHost string `json:"-"`
	StatusCode int    `json:"status"`
	Body       string `json:"body"`
	Expires    string `json:"expires"`
	Cached     bool   `json:"-"`
}

Robots is a single robots.txt response

func New

func New(sh string) *Robots

New creates a new Robot & sets the ID to the host Robots are handled on a per-host basis https://developers.google.com/webmasters/control-crawl-index/docs/robots_txt

func (*Robots) Expired

func (r *Robots) Expired() (bool, error)

Expired tells us if a robots.txt file needs to be refetched.

func (*Robots) SetBody

func (r *Robots) SetBody(b io.Reader) error

SetBody saves the body of a robots.txt file Since Group has unexported fields we must save the entire body, not just the group

func (*Robots) SetExpires

func (r *Robots) SetExpires() *Robots

SetExpires marks the date the robots.txt file should expire from cache

func (*Robots) SetStatusCode

func (r *Robots) SetStatusCode(code int) *Robots

SetStatusCode sets the HTTP response code

Jump to

Keyboard shortcuts

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