Giter Site home page Giter Site logo

ghr-self-updater's Introduction

ghr-self-update

A small library to create self-updating app in Go based on github releases

Usage

  1. Download the dependency

go get github.com/mJehanno/ghr-self-updater

go get github.com/blang/semver/v4

  1. Instanciate new Updater
//main.go 
package main

import(
    "context"

    "github.com/blang/semver/v4"
    selfupdate "github.com/mJehanno/ghr-self-updater"
)

func main() {
    ctx := context.Background()
    current = semver.MustParse("1.2.3")
    updater := selfupdate.New("mJehanno", "gtop", current, WithContext(ctx)) // ownerName, repoName, currentVersion, and a bunch of options that are not required.
}
  1. Check for latest and Update

either in two steps:

//main.go 
package main

import(
    "context"

    "github.com/blang/semver/v4"
    selfupdate "github.com/mJehanno/ghr-self-updater"
)

func main() {
    ctx := context.Background()
    current = semver.MustParse("1.2.3")
    updater := selfupdate.New("mJehanno", "gtop", current, WithContext(ctx)) // ownerName, repoName, currentVersion, and a bunch of options that are not required.

    latest,err := updater.CheckLatest()
    if err != nil {
        // handleErr
    }

    if !latest {
        // here you can ask for user consent for example
        err := updater.Update()
        if err != nil {
            // handleErr
        }
    }
}

or in one step:

//main.go 
package main

import(
    "context"

    "github.com/blang/semver/v4"
    selfupdate "github.com/mJehanno/ghr-self-updater"
)

func main() {
    ctx := context.Background()
    current = semver.MustParse("1.2.3")
    updater := selfupdate.New("mJehanno", "gtop", current, WithContext(ctx)) // ownerName, repoName, currentVersion, and a bunch of options that are not required.

    latest,err := updater.CheckAndUpdate()
    if err != nil {
        // handleErr
    }
}

ghr-self-updater's People

Contributors

mjehanno avatar

Stargazers

Vladimir Sokolovskiy avatar Yos avatar Tobiloba Ogundiyan avatar Sebastian avatar Rizwaan Abdul Kadir avatar Ayodeji O. avatar Mitch avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.