goatcounter

package
v0.0.0-...-a0a094e Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

package goatcounter implements the GoatCounter API

The GoatCounter API comprises multiple resources. Each is mapped to a Go type.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client is a type that implements methods for GoatCounter API client

func NewClient

func NewClient(code, token string) *Client

NewClient is a function that creates a new GoatCounter client

func (*Client) Count

func (c *Client) Count() (*Count, error)

Count is a method that implements GoatCounter /count endpoint

func (*Client) Do

func (c *Client) Do(ctx context.Context, method, url string, body io.Reader) ([]byte, error)

Do is a method that makes a GoatCounter API request

func (*Client) Exports

func (c *Client) Exports() ExportsInterface

Exports is a method that implements GoatCounter Exports endpoints Exports returns an implementation of ExportsInterface

func (*Client) Paths

func (c *Client) Paths() PathsInterface

Paths is a method that implements GoatCounter Paths endpoints Paths returns an implementation of PathsInterface

func (*Client) Sites

func (c *Client) Sites() SitesInterface

Sites is a method that implements GoatCounter Sites endpoints Sites returns an implementation of SitesInterface

func (*Client) Stats

func (c *Client) Stats() StatsInterface

Stats is a method that implements GoatCounter Stats endpoints Stats returns an implementation of StatsInterface

func (*Client) Users

func (c *Client) Users() UsersInterface

Users is a method that implements GoatCounter Users endpoints Users returns an implementation of UsersInterface

type ClientInterface

type ClientInterface interface {
	Do(context.Context, string, string, io.Reader) ([]byte, error)

	// This method is not part of a resource type
	Count() (*Count, error)

	// These correspond to resource types defined on the API
	// /exports
	// /paths
	// /sites
	// /stats
	// /users
	Exports() ExportsInterface
	Paths() PathsInterface
	Sites() SitesInterface
	Stats() StatsInterface
	Users() UsersInterface
}

ClientInterface is an interface that defines methods for GoatCounter API client

type Count

type Count struct {
}

type ErrorResponse

type ErrorResponse struct {
	// GError is used to avoid conflicting with the interface's Error method
	// The field must be Exported for JSON marshaling
	GError string `json:"error,omitempty"`
	Errors Errors `json:"errors,omitempty"`
}

ErrorResponse is a type that represents GoatCounter API error responses ErrorResponse implements the error interface

func (ErrorResponse) Error

func (e ErrorResponse) Error() string

type Errors

type Errors map[string][]string

type ExportsClient

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

ExportsClient is a type that implements methods for GoatCounter Exports endpoints

func (*ExportsClient) URL

func (c *ExportsClient) URL(path string) string

Url is a method that returns the endpoint's method URL

type ExportsInterface

type ExportsInterface interface {
	URL(string) string
}

ExportsInterface is an interface that defines methods for GoatCounter Exports endpoints

type Hit

type Hit struct {
	Count  int    `json:"count"`
	PathID int    `json:"path_id"`
	Path   string `json:"path"`
	Event  bool   `json:"event"`
	Title  string `json:"title"`
	Max    int    `json:"max"`
	Stats  []Stat `json:"stats"`
}

type HitsResponse

type HitsResponse struct {
	Hits []Hit `json:"hits"`
}

type Path

type Path struct {
	Event bool   `json:"event"`
	ID    int    `json:"id"`
	Path  string `json:"path"`
	Title string `json:"title"`
}

type PathsClient

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

PathsClient is a type that implements methods for GoatCounter Path endpoints

func (*PathsClient) List

func (c *PathsClient) List() (*PathsResponse, error)

List is a method that implements GoatCounter's /paths method

func (*PathsClient) URL

func (c *PathsClient) URL(path string) string

Url is a method that returns the endpoint's method URL

type PathsInterface

type PathsInterface interface {
	List() (*PathsResponse, error)
	URL(string) string
}

PathsInterface is an interface that defines methods on GoatCounter Paths endpoints

type PathsResponse

type PathsResponse struct {
	Paths []Path `json:"paths"`
	More  bool   `json:"more"`
}

type Site

type Site struct {
	CNAME        string       `json:"cname"`
	CNAMESetupAt time.Time    `json:"cname_setup_at"`
	Code         string       `json:"code"`
	CreatedAt    time.Time    `json:"created_at"`
	FirstHitAt   time.Time    `json:"first_hit_at"`
	ID           int          `json:"id"`
	LinkDomain   string       `json:"link_domain"`
	Parent       int          `json:"parent"`
	ReceivedData bool         `json:"received_data"`
	Settings     SiteSettings `json:"settings"`
	State        string       `json:"state"`
	UpdatedAt    time.Time    `json:"updated_at"`
	UserDefaults UserSettings `json:"user_defaults"`
}

type SiteSettings

type SiteSettings struct {
	AllowBosmang   bool     `json:"allow_bosmang"`
	AllowCounter   bool     `json:"allow_counter"`
	AllowEmbed     []string `json:"allow_embed"`
	Collect        int      `json:"collect"`
	CollectRegions []string `json:"collect_regions"`
	DataRetention  int      `json:"data_retention"`
	IgnoreIPs      []string `json:"ignore_ips"`
	Public         string   `json:"public"`
	Secret         string   `json:"secret"`
}

type SitesClient

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

func (*SitesClient) Get

func (c *SitesClient) Get(ID string) (*Site, error)

func (*SitesClient) List

func (c *SitesClient) List() (*SitesResponse, error)

func (*SitesClient) URL

func (c *SitesClient) URL(path string) string

type SitesInterface

type SitesInterface interface {
	Get(string) (*Site, error)
	List() (*SitesResponse, error)
	URL(string) string
}

SitesInterface is an interface that defines methods for GoatCounter Sites endpoints

type SitesResponse

type SitesResponse struct {
	Sites []Site `json:"sites"`
}

type Stat

type Stat struct {
	Day    string `json:"day"` // 2023-08-16
	Hourly []int  `json:"hourly"`
	Daily  int    `json:"daily"`
}

type StatsClient

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

StatsClient is a type that implements methods for GoatCounter Stats endpoints

func (*StatsClient) Hits

func (c *StatsClient) Hits() (*HitsResponse, error)

Hits is a method that implements GoatCounter /stats/hits

func (*StatsClient) Total

func (c *StatsClient) Total() (*Total, error)

Total is a method that implements GoatCounter /stats/total

func (*StatsClient) URL

func (c *StatsClient) URL(path string) string

Url is a method that returns the endpoint's method URL

type StatsInterface

type StatsInterface interface {
	Total() (*Total, error)
	Hits() (*HitsResponse, error)
	URL(string) string
}

StatsInterface is an interface that defines methods for GoatCounter Stats endpoints

type Token

type Token struct {
	Name        string `json:"name"`
	Permissions int    `json:"permissions"`
}

type Total

type Total struct {
	Total       int `json:"total"`
	TotalEvents int `json:"total_events"`
	TotalUTC    int `json:"total_utc"`
}

type User

type User struct {
	ID            int               `json:"id"`
	Site          int               `json:"site"`
	Email         string            `json:"email"`
	EmailVerified bool              `json:"email_verified"`
	TOTPVerified  bool              `json:"totp_verified"`
	Access        map[string]string `json:"access"`
	LoginAt       time.Time         `json:"login_at"`
	OpenAt        time.Time         `json:"open_at"`
	ResetAt       time.Time         `json:"reset_at,omitempty"`
	Settings      UserSettings      `json:"settings"`
	LastReportAt  time.Time         `json:"last_report_at"`
	UpdatedAt     time.Time         `json:"updated_at"`
	Token         Token             `json:"token"`
}

type UserSettings

type UserSettings struct {
	TwentyFourHours       bool      `json:"twenty_four_hours"`
	SundayStartsWeek      bool      `json:"sunday_starts_week"`
	Language              string    `json:"language"`
	DateFormat            string    `json:"date_format"`
	NumberFormat          int       `json:"number_format"`
	TimeZone              string    `json:"timezone"`
	Widgets               []Widget  `json:"widgets"`
	Views                 []View    `json:"views"`
	EmailReports          int       `json:"email_reports"`
	FewerNumbers          bool      `json:"fewer_numbers"`
	FewerNumbersLockUntil time.Time `json:"fewer_numbers_lock_until"`
}

type UsersClient

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

UsersClient is a type that implements GoatCounter Users endpoints

func (*UsersClient) Me

func (c *UsersClient) Me() (*User, error)

Me is a method that implements GoatCounter /me

func (*UsersClient) URL

func (c *UsersClient) URL(path string) string

Url is a method that returns the endpoint's method URL

type UsersInterface

type UsersInterface interface {
	Me() (*User, error)
	URL(string) string
}

UsersInterface is an interface that defines GoatCounter Users endpoints

type View

type View struct {
	Name   string `json:"name"`
	Filter string `json:"filter"`
	Daily  bool   `json:"daily"`
	Period string `json:"period"`
}

type Widget

type Widget struct {
	N string                 `json:"n"`
	S map[string]interface{} `json:"s"`
}

Jump to

Keyboard shortcuts

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