{"id":13367490,"url":"https://github.com/sanbornm/Go-selfupdate","last_synced_at":"2025-03-12T20:30:44.975Z","repository":{"id":11807768,"uuid":"14355761","full_name":"sanbornm/go-selfupdate","owner":"sanbornm","description":"Enable your Go applications to self update","archived":false,"fork":false,"pushed_at":"2024-08-17T15:01:54.000Z","size":109,"stargazers_count":1582,"open_issues_count":16,"forks_count":182,"subscribers_count":34,"default_branch":"master","last_synced_at":"2025-03-06T07:09:22.267Z","etag":null,"topics":["go","selfupdate"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sanbornm.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2013-11-13T06:17:43.000Z","updated_at":"2025-03-03T11:17:50.000Z","dependencies_parsed_at":"2024-01-08T16:09:30.457Z","dependency_job_id":"cd711b9a-2f08-4e51-b124-ff3787579273","html_url":"https://github.com/sanbornm/go-selfupdate","commit_stats":{"total_commits":68,"total_committers":21,"mean_commits":3.238095238095238,"dds":0.6176470588235294,"last_synced_commit":"e1c03e3d6ac7f1c43cf57c51a28cac3b31041ed0"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sanbornm%2Fgo-selfupdate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sanbornm%2Fgo-selfupdate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sanbornm%2Fgo-selfupdate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sanbornm%2Fgo-selfupdate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sanbornm","download_url":"https://codeload.github.com/sanbornm/go-selfupdate/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243290571,"owners_count":20267741,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["go","selfupdate"],"created_at":"2024-07-30T00:01:51.081Z","updated_at":"2025-03-12T20:30:44.646Z","avatar_url":"https://github.com/sanbornm.png","language":"Go","funding_links":[],"categories":["软件包","軟件包"],"sub_categories":["DevOps 工具"],"readme":"# go-selfupdate\n\n[![GoDoc](https://godoc.org/github.com/sanbornm/go-selfupdate/selfupdate?status.svg)](https://godoc.org/github.com/sanbornm/go-selfupdate/selfupdate)\n![CI/CD](https://github.com/sanbornm/go-selfupdate/actions/workflows/ci.yml/badge.svg)\n\nEnable your Golang applications to self update.  Inspired by Chrome based on Heroku's [hk](https://github.com/heroku/hk).\n\n## Features\n\n* Tested on Mac, Linux, Arm, and Windows\n* Creates binary diffs with [bsdiff](http://www.daemonology.net/bsdiff/) allowing small incremental updates\n* Falls back to full binary update if diff fails to match SHA\n\n## QuickStart\n\n### Install library and update/patch creation utility\n\n`go install github.com/sanbornm/go-selfupdate/cmd/go-selfupdate@latest`\n\n### Enable your App to Self Update\n\n`go get -u github.com/sanbornm/go-selfupdate/...`\n\n\tvar updater = \u0026selfupdate.Updater{\n\t\tCurrentVersion: version, // the current version of your app used to determine if an update is necessary\n\t\t// these endpoints can be the same if everything is hosted in the same place\n\t\tApiURL:         \"http://updates.yourdomain.com/\", // endpoint to get update manifest\n\t\tBinURL:         \"http://updates.yourdomain.com/\", // endpoint to get full binaries\n\t\tDiffURL:        \"http://updates.yourdomain.com/\", // endpoint to get binary diff/patches\n\t\tDir:            \"update/\",                        // directory relative to your app to store temporary state files related to go-selfupdate\n\t\tCmdName:        \"myapp\",                          // your app's name (must correspond to app name hosting the updates)\n\t\t// app name allows you to serve updates for multiple apps on the same server/endpoint\n\t}\n\n    // go look for an update when your app starts up\n\tgo updater.BackgroundRun()\n\t// your app continues to run...\n\n### Push Out and Update\n\n\tgo-selfupdate path-to-your-app the-version\n    go-selfupdate myapp 1.2\n\nBy default this will create a folder in your project called *public*. You can then rsync or transfer this to your webserver or S3. To change the output directory use `-o` flag.\n\nIf you are cross compiling you can specify a directory:\n\n    go-selfupdate /tmp/mybinares/ 1.2\n\nThe directory should contain files with the name, $GOOS-$ARCH. Example:\n\n    windows-386\n    darwin-amd64\n    linux-arm\n\nIf you are using [goxc](https://github.com/laher/goxc) you can output the files with this naming format by specifying this config:\n\n    \"OutPath\": \"{{.Dest}}{{.PS}}{{.Version}}{{.PS}}{{.Os}}-{{.Arch}}\",\n\n## Update Protocol\n\nUpdates are fetched from an HTTP(s) server. AWS S3 or static hosting can be used. A JSON manifest file is pulled first which points to the wanted version (usually latest) and matching metadata. SHA256 hash is currently the only metadata but new fields may be added here like signatures. `go-selfupdate` isn't aware of any versioning schemes. It doesn't know major/minor versions. It just knows the target version by name and can apply diffs based on current version and version you wish to move to. For example 1.0 to 5.0 or 1.0 to 1.1. You don't even need to use point numbers. You can use hashes, dates, etc for versions.\n\n\tGET yourserver.com/appname/linux-amd64.json\n\n\t200 ok\n\t{\n\t\t\"Version\": \"2\",\n\t\t\"Sha256\": \"...\" // base64\n\t}\n\n\tthen\n\n\tGET patches.yourserver.com/appname/1.1/1.2/linux-amd64\n\n\t200 ok\n\t[bsdiff data]\n\n\tor\n\n\tGET fullbins.yourserver.com/appname/1.0/linux-amd64.gz\n\n\t200 ok\n\t[gzipped executable data]\n\nThe only required files are `\u003cappname\u003e/\u003cos\u003e-\u003carch\u003e.json` and `\u003cappname\u003e/\u003clatest\u003e/\u003cos\u003e-\u003carch\u003e.gz` everything else is optional. If you wanted to you could skip using go-selfupdate CLI tool and generate these two files manually or with another tool.\n\n## Config\n\nUpdater Config options:\n\n\ttype Updater struct {\n\t\tCurrentVersion string    // Currently running version. `dev` is a special version here and will cause the updater to never update.\n\t\tApiURL         string    // Base URL for API requests (JSON files).\n\t\tCmdName        string    // Command name is appended to the ApiURL like http://apiurl/CmdName/. This represents one binary.\n\t\tBinURL         string    // Base URL for full binary downloads.\n\t\tDiffURL        string    // Base URL for diff downloads.\n\t\tDir            string    // Directory to store selfupdate state.\n\t\tForceCheck     bool      // Check for update regardless of cktime timestamp\n\t\tCheckTime      int       // Time in hours before next check\n\t\tRandomizeTime  int       // Time in hours to randomize with CheckTime\n\t\tRequester      Requester // Optional parameter to override existing HTTP request handler\n\t\tInfo           struct {\n\t\t\tVersion string\n\t\t\tSha256  []byte\n\t\t}\n\t\tOnSuccessfulUpdate func() // Optional function to run after an update has successfully taken place\n\t}\n\n### Restart on update\n\nIt is common for an app to want to restart to apply the update. `go-selfupdate` gives you a hook to do that but leaves it up to you on how and when to restart as it differs for all apps. If you have a service restart application like Docker or systemd you can simply exit and let the upstream app start/restart your application. Just set the `OnSuccessfulUpdate` hook:\n\n\tu.OnSuccessfulUpdate = func() { os.Exit(0) }\n\nOr maybe you have a fancy graceful restart library/func:\n\n\tu.OnSuccessfulUpdate = func() { gracefullyRestartMyApp() }\n\n## State\n\ngo-selfupdate will keep a Go time.Time formatted timestamp in a file named `cktime` in folder specified by `Updater.Dir`. This can be useful for debugging to see when the next update can be applied or allow other applications to manipulate it.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsanbornm%2FGo-selfupdate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsanbornm%2FGo-selfupdate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsanbornm%2FGo-selfupdate/lists"}