Documentation
¶
Overview ¶
Package autodeployment provides a simple, standalone auto-updater for Go applications.
Overview ¶
This package enables your Go applications to automatically update themselves by checking a deployment API at regular intervals. It supports SHA256 verification, time synchronization, and executable permission handling.
Quick Start ¶
package main
import (
"os"
"github.com/LucazPlays/AutoDeploymentLib-Go"
)
func main() {
updater := autodeployment.New("your-project-uuid", "your-project-key")
updater.Start()
// Your application logic here
select {}
}
Features ¶
- Automatic update checking at configurable intervals
- SHA256 hash verification for download integrity
- Time synchronization with server to prevent unnecessary updates
- Automatic executable permission handling (0755)
- Backup creation before update installation
- Zero external dependencies (Go standard library only)
Configuration ¶
Set custom API root:
updater.SetAPIRoot("https://api.insights-api.top/deployment/")
Set custom update interval:
updater.SetUpdateInterval(60 * time.Second)
Time Synchronization ¶
The updater synchronizes with the server time to ensure consistent timestamp comparisons, even if the local system clock is inaccurate.
info := updater.GetTimeInfo()
fmt.Printf("Server: %d, Local: %d, Diff: %dms\n",
info.ServerTime, info.LocalTime, info.TimeDiff)
API Documentation ¶
For full API documentation, visit: https://pkg.go.dev/github.com/LucazPlays/AutoDeploymentLib-Go
Index ¶
- type ReleaseInfo
- type TimeInfo
- type Updater
- func (u *Updater) GetAdjustedLocalTime() int64
- func (u *Updater) GetLocalTime() int64
- func (u *Updater) GetServerTime() int64
- func (u *Updater) GetTimeDiff() int64
- func (u *Updater) GetTimeInfo() TimeInfo
- func (u *Updater) SetAPIRoot(apiRoot string)
- func (u *Updater) SetUpdateInterval(interval time.Duration)
- func (u *Updater) Start() error
- func (u *Updater) Stop()
- func (u *Updater) SyncTime()
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ReleaseInfo ¶
type ReleaseInfo struct {
// LastModifiedEpochMs is the timestamp (in milliseconds) when this release was last modified.
LastModifiedEpochMs int64 `json:"lastModifiedEpochMs"`
// DownloadURL is the relative or absolute URL to download the release.
DownloadURL string `json:"downloadUrl"`
// SHA256 is the SHA256 checksum of the release file.
SHA256 string `json:"sha256"`
}
ReleaseInfo represents the metadata of a release from the deployment API.
type TimeInfo ¶
type TimeInfo struct {
// ServerTime is the current time on the deployment server (Unix milliseconds).
ServerTime int64 `json:"serverTime"`
// LocalTime is the current local time (Unix milliseconds).
LocalTime int64 `json:"localTime"`
// AdjustedLocalTime is the local time adjusted by the server time offset.
AdjustedLocalTime int64 `json:"adjustedLocalTime"`
// TimeDiff is the difference between server and local time (Server - Local).
TimeDiff int64 `json:"timeDiff"`
}
TimeInfo contains timing information for debugging time synchronization issues.
type Updater ¶
type Updater struct {
// contains filtered or unexported fields
}
Updater provides automatic update checking and installation for applications.
func New ¶
New creates a new Updater instance.
The uuid and key are obtained from your deployment API project settings.
func (*Updater) GetAdjustedLocalTime ¶
GetAdjustedLocalTime returns the local time adjusted by the server time offset.
func (*Updater) GetLocalTime ¶
GetLocalTime returns the current local time in Unix milliseconds.
func (*Updater) GetServerTime ¶
GetServerTime retrieves the current time from the deployment API. Returns Unix milliseconds, or 0 on error.
func (*Updater) GetTimeDiff ¶
GetTimeDiff returns the time difference between server and local clock. Positive value means server is ahead, negative means local is ahead.
func (*Updater) GetTimeInfo ¶
GetTimeInfo returns a struct containing all timing information useful for debugging.
func (*Updater) SetAPIRoot ¶
SetAPIRoot sets the base URL for the deployment API. Default: "https://api.insights-api.top/deployment/"
func (*Updater) SetUpdateInterval ¶
SetUpdateInterval sets how often to check for updates. Default: 30 seconds