updater

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: May 24, 2020 License: MIT Imports: 5 Imported by: 1

README

Github Release Check

This is a simple Go lib to handle updates. Small and easy to use lib.

go get github.com/yitsushi/github-release-check
Sample code
package main

import GRC "github.com/yitsushi/github-release-check"
import "fmt"

const (
  RepoOwner string = "yitsushi"
  RepoName  string = "Server-For-React"
  Version   string = "v1.0"
)

func main() {
  needUpdate, releaseInfo, err := GRC.Check(RepoOwner, RepoName, Version)

  if err != nil {
    panic(err)
  }

  if needUpdate {
    fmt.Printf("Please update from %s to %s at %s", Version, releaseInfo.TagName, releaseInfo.HTMLURL)
  } else {
    fmt.Println("Application status: Up to date.")
  }
}

It does not return with the full Release response object but only with useful fields that related to an application update request.

Why release?

Because I need to test the API Endpoint somewhere and why not with the same repo. So nothing more (yet)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Asset

type Asset struct {
	ID                 int       `json:"id"`
	URL                string    `json:"url"`
	Name               string    `json:"name"`
	Size               int       `json:"size"`
	CreatedAt          time.Time `json:"created_at"`
	UpdatedAt          time.Time `json:"updated_at"`
	BrowserDownloadURL string    `json:"browser_download_url"`
}

Asset structure from GitHub API

type Release

type Release struct {
	ID          int       `json:"id"`
	URL         string    `json:"url"`
	AssetURL    string    `json:"asset_url"`
	UploadURL   string    `json:"upload_url"`
	HTMLURL     string    `json:"html_url"`
	TagName     string    `json:"tag_name"`
	Name        string    `json:"name"`
	CreatedAt   time.Time `json:"created_at"`
	PublishedAt time.Time `json:"published_at"`
	Prerelease  bool      `json:"prerelease"`
	Assets      []Asset   `json:"assets"`
}

Release structure from GitHub API

func Check

func Check(repoOwner string, repoName string, currentVersion string) (bool, *Release, error)

Check GitHub's Release API endpoint for the latest release (tag name) and returns with true or false as has it an update or don't and the latest *release as a struct and an error if something went wrong

Jump to

Keyboard shortcuts

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