online

package
v0.11.3 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2023 License: LGPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Package online is for simple HTTP interactions with the GitHub API. It is used to fetch the latest release information of the program.

Index

Examples

Constants

View Source
const (
	// ReleaseAPI GitHub API v3 releases endpoint.
	// See: https://developer.github.com/v3/repos/releases/
	ReleaseAPI = "https://api.github.com/repos/bengarrett/retrotxtgo/releases/latest"
)

Variables

View Source
var (
	ErrJSON = errors.New("the response body syntax is not json")
	ErrMash = errors.New("cannot unmarshal the json response body")
)

Functions

func Get

func Get(url, etag string) (*http.Response, []byte, error)

Get fetches a URL and returns both its response and body. If an etag is provided a "If-None-Match" header request will be included.

func Ping

func Ping(url string) (bool, error)

Ping requests a URL and reports whether if the status is successful. A server response status code between 200 and 299 is considered a success.

Example
package main

import (
	"fmt"

	"github.com/bengarrett/retrotxtgo/pkg/online"
)

func main() {
	ok, _ := online.Ping("https://example.org")
	fmt.Print(ok)
}
Output:

true

Types

type API

type API map[string]interface{}

API interface to store the JSON results from GitHub.

func Endpoint

func Endpoint(url, etag string) (bool, API, error)

Endpoint requests an API endpoint from the URL. A HTTP ETag can be provided to validate local data cache against the server. It also reports whether the etag value matches the server ETag header.

Jump to

Keyboard shortcuts

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