adstxt

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2021 License: MIT Imports: 10 Imported by: 0

README

adstxt

GoDoc

ads.txt resolver for Go. This implementation is based on v1.03 of the ads.txt spec as published by the IAB Tech Lab.

Examples

Resolve ads.txt from a domain using the default HTTP client:

adstxt, err := adstxt.DefaultResolve("www.example.com")

Customize the HTTP client. Consider using this package's CheckRedirect function, because it implements the IAB-specified external redirect rules.

client := &http.Client{
	Timeout: 1 * time.Minute,
	CheckRedirect: adstxt.CheckRedirect,
}
adstxt, err := adstxt.Resolve(client, "www.example.com")

Parse ads.txt data without making an HTTP request

rawAdsTxt := strings.NewReader(`# comment
foo,bar,DIRECT,baz
three,four,RESELLER`)
adstxt, err := adstxt.Parse(rawAdsTxt)

See the GoDoc link for a description of the parsed ads.txt format.

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckRedirect

func CheckRedirect(req *http.Request, via []*http.Request) error

CheckRedirect is a http.Client CheckRedirect function that implements at-most-one external redirect as specified in section 3.1 of the ads.txt spec (v. 1.03)

Types

type AdsTxt

type AdsTxt struct {
	Records   []Record
	Variables map[Variable][]string
}

func DefaultResolve

func DefaultResolve(host string) (AdsTxt, error)

DefaultResolve requests and parses ads.txt using a default HTTP client

func Parse

func Parse(in io.Reader) (AdsTxt, error)

Parse parses ads.txt from in

Example
rawAdsTxt := strings.NewReader(`# comment
foo,bar,DIRECT,baz
one,two,RESELLER
three,four,RESELLER

# another comment
contact=foo
contact=foobar
subdomain=bar #comment`)
adstxt, err := Parse(rawAdsTxt)

fmt.Printf("error: %t\n", err != nil)
fmt.Printf("record count: %d\n", len(adstxt.Records))
fmt.Printf("variable count: %d\n", len(adstxt.Variables))
Output:

error: false
record count: 3
variable count: 2

func Resolve

func Resolve(doer Doer, host string) (AdsTxt, error)

Resolve requests and parses ads.txt from the provided host

func (AdsTxt) String

func (a AdsTxt) String() string

type Doer

type Doer interface {
	Do(*http.Request) (*http.Response, error)
}

type Record

type Record struct {
	AdSystemDomain  string
	SellerAccountID string
	Relationship    RelationshipType
	CertAuthorityID string
	Extension       string
}

type RelationshipType

type RelationshipType int
const (
	RelationshipTypeUnspecified RelationshipType = iota
	Direct
	Reseller
)

type Variable

type Variable int
const (
	VariableUnspecified Variable = iota
	Contact
	Subdomain
	InventoryPartnerDomain
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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