pagespeed

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2024 License: MIT Imports: 8 Imported by: 0

README

go-pagespeed

Go Report Card Go Reference

Golang module to the PageSpeed Insights API v5.

Google Docs: Get Started with the PageSpeed Insights API

Get:

go get github.com/g0rbe/go-pagespeed@latest

Get the latest tag (if Go module proxy is not updated):

go get "github.com/g0rbe/go-pagespeed@$(curl -s 'https://api.github.com/repos/g0rbe/go-pagespeed/tags' | jq -r '.[0].name')"

Get the latest commit (if Go module proxy is not updated):

go get "github.com/g0rbe/go-pagespeed@$(curl -s 'https://api.github.com/repos/g0rbe/go-pagespeed/commits' | jq -r '.[0].sha')"

TODO

  • LighthouseResult.i18n
  • LighthouseResult.fullPageScreenshot

Documentation

Index

Examples

Constants

View Source
const (
	CategoryAccessibility = "ACCESSIBILITY"
	CategoryBestPractices = "BEST_PRACTICES"
	CategoryPerformance   = "PERFORMANCE"
	CategorySEO           = "SEO"
	CategoryPWA           = "PWA"
)

Possible values for category paramater

View Source
const (
	StrategyDesktop = "dektop"
	StrategyMobile  = "mobile"
)

Possible values for strategy paramater

View Source
const (
	ApiEndpoint = "https://www.googleapis.com/pagespeedonline/v5/runPagespeed"
)

Variables

View Source
var (
	// Shorthand to include every category
	CategoryAll = []string{CategoryAccessibility, CategoryBestPractices, CategoryPerformance, CategorySEO, CategoryPWA}
)

Functions

This section is empty.

Types

type Audit

type Audit struct {
	ID               string  `json:"id"`
	Title            string  `json:"title"`
	Description      string  `json:"description"`
	Score            float32 `json:"score"`
	ScoreDisplayMode string  `json:"scoreDisplayMode"`
}

type AuditRef

type AuditRef struct {
	ID     string  `json:"id"`
	Weight float32 `json:"weight"`
	Group  string  `json:"group"`
}

type Category

type Category struct {
	ID                string     `json:"id"`
	Title             string     `json:"title"`
	Description       string     `json:"description"`
	Score             float32    `json:"score"`
	ManualDescription string     `json:"manualDescription"`
	AuditRefs         []AuditRef `json:"auditRefs"`
}

type CategoryGroup

type CategoryGroup struct {
	Title       string `json:"title"`
	Description string `json:"description"`
}

type ConfigSettings

type ConfigSettings struct {
	EmulatedFormFactor string   `json:"emulatedFormFactor"`
	FormFactor         string   `json:"formFactor"`
	Locale             string   `json:"locale"`
	FinalUrl           string   `json:"finalUrl"`
	OnlyCategories     []string `json:"onlyCategories"`
	Channel            string   `json:"channel"`
}

type Distribution

type Distribution struct {
	Min        int     `json:"min"`
	Max        int     `json:"max"`
	Proportion float32 `json:"proportion"`
}

type Entity

type Entity struct {
	Name           string   `json:"name"`
	IsFirstParty   bool     `json:"isFirstParty"`
	IsUnrecognized bool     `json:"isUnrecognized"`
	Origins        []string `json:"origins"`
}

type Environment

type Environment struct {
	NetworkUserAgent string  `json:"networkUserAgent"`
	HostUserAgent    string  `json:"hostUserAgent"`
	BenchmarkIndex   float32 `json:"benchmarkIndex"`
}

type LighthouseResult

type LighthouseResult struct {
	RequestedUrl      string                   `json:"requestedUrl"`
	FinalUrl          string                   `json:"finalUrl"`
	MainDocumentUrl   string                   `json:"mainDocumentUrl"`
	FinalDisplayedUrl string                   `json:"finalDisplayedUrl"`
	LighthouseVersion string                   `json:"lighthouseVersion"`
	UserAgent         string                   `json:"userAgent"`
	FetchTime         string                   `json:"fetchTime"`
	Environment       Environment              `json:"environment"`
	RunWarnings       []string                 `json:"runWarnings"`
	ConfigSettings    ConfigSettings           `json:"configSettings"`
	Audits            map[string]Audit         `json:"audits"`
	Categories        map[string]Category      `json:"categories"`
	CategoryGroups    map[string]CategoryGroup `json:"categoryGroups"`
	RuntimeError      RuntimeError             `json:"runtimeError"`
	Timing            Timing                   `json:"timing"`
	Entities          []Entity                 `json:"entities"`
}

type LighthouseScores added in v0.2.0

type LighthouseScores struct {
	URL           string `json:",omitempty" yaml:",omitempty"`
	Performance   int    `json:",omitempty" yaml:",omitempty"`
	Accessibility int    `json:",omitempty" yaml:",omitempty"`
	BestPractices int    `json:",omitempty" yaml:",omitempty"`
	SEO           int    `json:",omitempty" yaml:",omitempty"`
	PWA           int    `json:",omitempty" yaml:",omitempty"`
	Error         error  `json:",omitempty" yaml:",omitempty"`
}

func RunLighthouse added in v0.3.0

func RunLighthouse(u string, opts *Options) (*LighthouseScores, error)
Example
r, err := pagespeed.RunPagespeed(randomURL(), pagespeed.FullAnalysisWithKey(os.Getenv("GOOGLE_CLOUD_KEY")))
if err != nil {
	// handle error
}

fmt.Printf("%#v\n", r)

func (LighthouseScores) String added in v0.2.0

func (l LighthouseScores) String() string

func (*LighthouseScores) Total added in v0.3.0

func (l *LighthouseScores) Total() int

type LighthouseWorker added in v0.3.0

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

func NewLighthouseWorker added in v0.3.0

func NewLighthouseWorker(opt *Options, numWorker int, lenBuf int) *LighthouseWorker

func (*LighthouseWorker) Close added in v0.3.0

func (w *LighthouseWorker) Close() error

func (*LighthouseWorker) Get added in v0.3.0

func (*LighthouseWorker) NumTask added in v0.3.0

func (w *LighthouseWorker) NumTask() int

func (*LighthouseWorker) NumWorker added in v0.3.0

func (w *LighthouseWorker) NumWorker() int

func (*LighthouseWorker) Put added in v0.3.0

func (w *LighthouseWorker) Put(u string)

func (*LighthouseWorker) StartWorker added in v0.3.0

func (w *LighthouseWorker) StartWorker()

func (*LighthouseWorker) StartWorkers added in v0.3.0

func (w *LighthouseWorker) StartWorkers(n int)

func (*LighthouseWorker) StopWorker added in v0.3.0

func (w *LighthouseWorker) StopWorker() bool

type LoadingExperience

type LoadingExperience struct {
	ID              string            `json:"id"`
	Metrics         map[string]Metric `json:"metrics"`
	OverallCategory string            `json:"overall_category"`
	InitialURL      string            `json:"initial_url"`
}

type Metric

type Metric struct {
	Percentile    int            `json:"percentile"`
	Distributions []Distribution `json:"distributions"`
	Category      string         `json:"category"`
}

type Options

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

func FullAnalysis added in v0.3.0

func FullAnalysis() *Options

func FullAnalysisWithKey added in v0.3.0

func FullAnalysisWithKey(k string) *Options

func NewOptions added in v0.3.0

func NewOptions() *Options

func (*Options) RequestURL

func (o *Options) RequestURL(u string) string

RequestURL creates the request URL to analyze URL u.

func (*Options) SetCategories added in v0.3.0

func (o *Options) SetCategories(c []string)

func (*Options) SetKey added in v0.3.0

func (o *Options) SetKey(v string)

type Result

type Result struct {
	CaptchaResult           string            `json:"captchaResult"`
	Kind                    string            `json:"kind"`
	ID                      string            `json:"id"`
	LoadingExperience       LoadingExperience `json:"loadingExperience"`
	OriginLoadingExperience LoadingExperience `json:"originLoadingExperience"`
	LighthouseResult        LighthouseResult  `json:"lighthouseResult"`
	AnalysisUTCTimestamp    time.Time         `json:"analysisUTCTimestamp"`
}

func RunPagespeed added in v0.3.0

func RunPagespeed(u string, opt *Options) (*Result, error)
Example
r, err := pagespeed.RunPagespeed(randomURL(), pagespeed.FullAnalysisWithKey(os.Getenv("GOOGLE_CLOUD_KEY")))
if err != nil {
	// handle error
}

fmt.Printf("%#v\n", r)

func (*Result) LighthouseScores added in v0.2.0

func (r *Result) LighthouseScores() *LighthouseScores

type RuntimeError

type RuntimeError struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

func (RuntimeError) Error added in v0.3.0

func (r RuntimeError) Error() string

func (*RuntimeError) UnmarshalJSON added in v0.3.0

func (r *RuntimeError) UnmarshalJSON(data []byte) error

type Timing

type Timing struct {
	Total float32 `json:"total"`
}

Jump to

Keyboard shortcuts

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