autodeployment

package module
v0.0.0-...-ba542b4 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2026 License: MIT Imports: 10 Imported by: 0

README

AutoDeploymentLib-Go

Go Reference Go Version License

A simple, standalone auto-updater for Go applications with SHA256 verification and time synchronization.

Installation

go get github.com/LucazPlays/AutoDeploymentLib-Go

Quick Start

package main

import (
	"os"
	"time"
	"github.com/LucazPlays/AutoDeploymentLib-Go"
)

func main() {
	updater := autodeployment.New("your-project-uuid", "your-project-key")
	
	// Optional configuration
	updater.SetAPIRoot("https://api.insights-api.top/deployment/")
	updater.SetUpdateInterval(30 * time.Second)
	
	// Start the updater
	if err := updater.Start(); err != nil {
		panic(err)
	}
	
	// Your application logic here
	// ...
	
	select {}
}

Features

  • Automatic Updates - Periodically checks for new releases from the deployment API
  • SHA256 Verification - Ensures download integrity with cryptographic hash verification
  • Time Synchronization - Syncs with server time to prevent unnecessary updates
  • Executable Permissions - Automatically sets 0755 permissions after update
  • Backup Creation - Creates .bak backup before installing updates
  • Zero Dependencies - Uses only the Go standard library

API Documentation

Updater
// Create a new updater
updater := autodeployment.New(uuid, key)

// Configure API root (default: https://api.insights-api.top/deployment/)
updater.SetAPIRoot("https://api.insights-api.top/deployment/")

// Configure update interval (default: 30 seconds)
updater.SetUpdateInterval(30 * time.Second)

// Start the updater
updater.Start()

// Stop the updater
updater.Stop()
Time Synchronization
// Sync time with server (called automatically by Start)
updater.SyncTime()

// Get all timing information for debugging
info := updater.GetTimeInfo()
// info.ServerTime        - Server time (Unix ms)
// info.LocalTime         - Local time (Unix ms)
// info.TimeDiff          - Server - Local (ms)

// Get individual values
serverTime := updater.GetServerTime()
localTime := updater.GetLocalTime()
timeDiff := updater.GetTimeDiff()

License

MIT License - see LICENSE for details.

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

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

func New(uuid, key string) *Updater

New creates a new Updater instance.

The uuid and key are obtained from your deployment API project settings.

func (*Updater) GetAdjustedLocalTime

func (u *Updater) GetAdjustedLocalTime() int64

GetAdjustedLocalTime returns the local time adjusted by the server time offset.

func (*Updater) GetLocalTime

func (u *Updater) GetLocalTime() int64

GetLocalTime returns the current local time in Unix milliseconds.

func (*Updater) GetServerTime

func (u *Updater) GetServerTime() int64

GetServerTime retrieves the current time from the deployment API. Returns Unix milliseconds, or 0 on error.

func (*Updater) GetTimeDiff

func (u *Updater) GetTimeDiff() int64

GetTimeDiff returns the time difference between server and local clock. Positive value means server is ahead, negative means local is ahead.

func (*Updater) GetTimeInfo

func (u *Updater) GetTimeInfo() TimeInfo

GetTimeInfo returns a struct containing all timing information useful for debugging.

func (*Updater) SetAPIRoot

func (u *Updater) SetAPIRoot(apiRoot string)

SetAPIRoot sets the base URL for the deployment API. Default: "https://api.insights-api.top/deployment/"

func (*Updater) SetUpdateInterval

func (u *Updater) SetUpdateInterval(interval time.Duration)

SetUpdateInterval sets how often to check for updates. Default: 30 seconds

func (*Updater) Start

func (u *Updater) Start() error

Start begins the automatic update checker. It first synchronizes time with the server, then starts checking for updates in a background goroutine at the configured interval.

func (*Updater) Stop

func (u *Updater) Stop()

Stop halts the update checker.

func (*Updater) SyncTime

func (u *Updater) SyncTime()

SyncTime synchronizes the local clock with the server clock. This is called automatically by Start(), but can be called manually if needed.

Jump to

Keyboard shortcuts

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