Keygen SDK for Go. Integrate license activation and automatic updates for Go binaries.

Keygen Go SDK godoc reference

Package keygen allows Go programs to license and remotely update themselves using the keygen.sh service.

Usage

keygen.Validate(fingerprint)

To validate a license, configure keygen.Account and keygen.Product with your Keygen account details. Then prompt the user for their license token and set keygen.Token.

The Validate method accepts zero or more fingerprints, which can be used to scope a license validation to a particular fingerprint. It will return a License object as well as any validation errors that occur. The License object can be used to perform additional actions, such as license.Activate(fingerprint).

license, err := keygen.Validate(fingerprint)
switch {
case err == keygen.ErrLicenseNotActivated:
  fmt.Println("License is not activated!")

  return
case err == keygen.ErrLicenseExpired:
  fmt.Println("License is expired!")

  return
case err != nil:
  fmt.Println("License is invalid!")

  return
}

fmt.Println("License is valid!")

keygen.Upgrade(currentVersion)

Check for an upgrade. When an upgrade is available, a Release will be returned which will allow the update to be installed, replacing the currently running binary. When an upgrade is not available, an ErrUpgradeNotAvailable error will be returned indicating the current version is up-to-date.

release, err := keygen.Upgrade(currentVersion)
switch {
case err == keygen.ErrUpgradeNotAvailable:
  fmt.Println("No upgrade available, already at the latest version!")

  return
case err != nil:
  fmt.Println("Upgrade check failed!")

  return
}

if err := release.Install(); err != nil {
  fmt.Println("Upgrade install failed!")

  return
}

fmt.Println("Upgrade complete! Please restart.")

keygen.Genuine(licenseKey, schemeCode)

Cryptographically verify and decode a signed license key. This is useful for checking if a license key is genuine in offline or air-gapped environments. Returns the key's decoded dataset and any errors that occurred during cryptographic verification, e.g. ErrLicenseNotGenuine.

Requires that keygen.PublicKey is set.

dataset, err := keygen.Genuine(licenseKey, keygen.SchemeCodeEd25519)
switch {
case err == keygen.ErrLicenseNotGenuine:
  fmt.Println("License key is not genuine!")

  return
case err != nil:
  fmt.Println("Genuine check failed!")

  return
}

fmt.Printf("Decoded dataset: %s\n", dataset)

Examples

License activation

import "github.com/keygen-sh/keygen-go"

func activate() error {
  keygen.Account = os.Getenv("KEYGEN_ACCOUNT")
  keygen.Product = os.Getenv("KEYGEN_PRODUCT")
  keygen.Token = os.Getenv("KEYGEN_TOKEN")

  // The current device's fingerprint (could be e.g. MAC, mobo ID, GUID, etc.)
  fingerprint := uuid.New().String()

  // Validate the license for the current fingerprint
  license, err := keygen.Validate(fingerprint)
  switch {
  case err == keygen.ErrLicenseNotActivated:
    // Activate the current fingerprint
    machine, err := license.Activate(fingerprint)
    switch {
    case err == keygen.ErrMachineLimitExceeded:
      fmt.Println("Machine limit has been exceeded!")

      return err
    case err != nil:
      fmt.Println("Machine activation failed!")

      return err
    }
  case err == keygen.ErrLicenseExpired:
    fmt.Println("License is expired!")

    return err
  case err != nil:
    fmt.Println("License is invalid!")

    return err
  }

  fmt.Println("License is activated!")
}

Automatic upgrade example

import "github.com/keygen-sh/keygen-go"

func upgrade() error {
  keygen.Account = os.Getenv("KEYGEN_ACCOUNT")
  keygen.Product = os.Getenv("KEYGEN_PRODUCT")
  keygen.Token = os.Getenv("KEYGEN_TOKEN")

  // The current version of the program
  currentVersion := "1.0.0"

  // Check for upgrade
  release, err := keygen.Upgrade(currentVersion)
  switch {
  case err == keygen.ErrUpgradeNotAvailable:
    fmt.Println("No upgrade available, already at the latest version!")

    return nil
  case err != nil:
    fmt.Println("Upgrade check failed!")

    return err
  }

  // Download the upgrade and install it
  if err := release.Install(); err != nil {
    return err
  }

  fmt.Println("Upgrade complete! Please restart.")
}
Owner
Keygen
A dead-simple software licensing and distribution API built for developers
Keygen
Similar Resources

planet is a blockchain built using Cosmos SDK and Tendermint and created with Starport.

planet planet is a blockchain built using Cosmos SDK and Tendermint and created with Starport. Get started starport chain serve serve command install

Oct 31, 2021

An easy-to-use unofficial SDK for Feishu and Lark Open Platform

go-lark go-lark is an easy-to-use unofficial SDK for Feishu and Lark Open Platform. go-lark implements messaging APIs, with full-fledged supports on b

Jan 2, 2023

The Fabric Token SDK is a set of API and services that lets developers create token-based distributed application on Hyperledger Fabric.

The Fabric Token SDK is a set of API and services that let developers create token-based distributed application on Hyperledger Fabric.

Dec 14, 2022

A decentralized vinyl marketplace demo built with Go, Cosmos SDK and Starport

emusicchain emusicchain is a blockchain built using Cosmos SDK and Tendermint and created with Starport. Get started starport chain serve serve comma

Dec 5, 2021

A SDK development package developed in go language and connected to dechain

Platform introduction Dechain go SDK is a SDK development package developed in go language and connected to dechain. This SDK can be provided to go cl

Dec 14, 2021

Go package providing opinionated tools and methods for working with the `aws-sdk-go/service/cloudfront` package.

go-aws-cloudfront Go package providing opinionated tools and methods for working with the aws-sdk-go/service/cloudfront package. Documentation Tools $

Feb 2, 2022

AWS SDK for the Go programming language.

AWS SDK for Go aws-sdk-go is the official AWS SDK for the Go programming language. Checkout our release notes for information about the latest bug fix

Dec 31, 2022

A Facebook Graph API SDK For Go.

A Facebook Graph API SDK In Golang This is a Go package that fully supports the Facebook Graph API with file upload, batch request and marketing API.

Dec 12, 2022
Comments
  • linux get -u failed #go version go1.17.10 uname -a Linux kali 5.15.0-kali3-amd64

    linux get -u failed #go version go1.17.10 uname -a Linux kali 5.15.0-kali3-amd64

    ─# go get -u "github.com/keygen-sh/keygen-go"

    cd /root/go/GOCODE/src/golang.org/x/sys; git pull --ff-only

    From https://go.googlesource.com/sys bc2c85a..c0bba94 master -> origin/master

    • [new branch] internal-branch.go1.19-vendor -> origin/internal-branch.go1.19-vendor error: Your local changes to the following files would be overwritten by merge: cpu/cpu_gccgo_x86.c unix/asm_linux_loong64.s unix/errors_freebsd_386.go unix/errors_freebsd_amd64.go unix/errors_freebsd_arm.go unix/errors_freebsd_arm64.go unix/linux/Dockerfile unix/linux/types.go unix/mksysnum.go unix/syscall_aix.go unix/syscall_bsd.go unix/syscall_darwin.go unix/syscall_freebsd.go unix/syscall_freebsd_386.go unix/syscall_freebsd_amd64.go unix/syscall_freebsd_arm.go unix/syscall_freebsd_arm64.go unix/syscall_illumos.go unix/syscall_linux.go unix/syscall_linux_loong64.go unix/syscall_linux_riscv64.go unix/syscall_openbsd_mips64.go unix/syscall_solaris.go unix/syscall_unix.go unix/syscall_unix_test.go unix/syscall_zos_test.go unix/types_darwin.go unix/types_freebsd.go unix/types_solaris.go unix/zerrors_freebsd_386.go unix/zerrors_freebsd_amd64.go unix/zerrors_freebsd_arm.go unix/zerrors_freebsd_arm64.go unix/zerrors_linux.go unix/zerrors_linux_386.go unix/zerrors_linux_amd64.go unix/zerrors_linux_arm.go unix/zerrors_linux_arm64.go unix/zerrors_linux_loong64.go unix/zerrors_linux_mips.go unix/zerrors_linux_mips64.go unix/zerrors_linux_mips64le.go unix/zerrors_linux_mipsle.go unix/zerrors_linux_ppc.go unix/zerrors_linux_ppc64.go unix/zerrors_linux_ppc64le.go unix/zerrors_linux_riscv64.go unix/zerrors_linux_s390x.go unix/zerrors_linux_sparc64.go unix/zsyscall_freebsd_386.go unix/zsyscall_freebsd_amd64.go unix/zsyscall_freebsd_arm.go unix/zsyscall_freebsd_arm64.go unix/zsyscall_linux_loong64.go unix/zsyscall_linux_riscv64.go unix/zsyscall_solaris_amd64.go unix/zsysnum_freebsd_386.go unix/zsysnum_freebsd_amd64.go unix/zsysnum_freebsd_arm.go unix/zsysnum_freebsd_arm64.go unix/zsysnum_linux_loong64.go unix/zsysnum_linux_riscv64.go unix/ztypes_darwin_amd64.go unix/ztypes_darwin_arm64.go unix/ztypes_freebsd_386.go unix/ztypes_freebsd_amd64.go unix/ztypes_freebsd_arm.go unix/ztypes_freebsd_arm64.go unix/ztypes_linux.go unix/ztypes_linux_386.go unix/ztypes_linux_amd64.go unix/ztypes_linux_arm.go unix/ztypes_linux_arm64.go unix/ztypes_linux_loong64.go unix/ztypes_linux_mips.go unix/ztypes_linux_mips64.go unix/ztypes_linux_mips64le.go unix/ztypes_linux_mipsle.go unix/ztypes_linux_ppc.go unix/ztypes_linux_ppc64.go unix/ztypes_linux_ppc64le.go unix/ztypes_linux_riscv64.go unix/ztypes_linux_s390x.go unix/ztypes_linux_sparc64.go unix/ztypes_solaris_amd64.go windows/syscall_windows.go windows/types_windows.go windows/zsyscall_windows.go Please commit your changes or stash them before you merge. Aborting package golang.org/x/sys/cpu: exit status 1

    cd /root/go/GOCODE/src/golang.org/x/crypto; git pull --ff-only

    From https://go.googlesource.com/crypto 7b82a4e..0559593 master -> origin/master

    • [new branch] internal-branch.go1.19-vendor -> origin/internal-branch.go1.19-vendor error: Your local changes to the following files would be overwritten by merge: acme/acme.go acme/autocert/cache.go acme/autocert/internal/acmetest/ca.go acme/jws.go acme/jws_test.go acme/rfc8555.go acme/rfc8555_test.go
  • ../github.com/oasisprotocol/curve25519-voi/internal/toolchain/constraints.go:48:6: undefined: __SOFTWARE_REQUIRES_GO_VERSION_1_18__

    ../github.com/oasisprotocol/curve25519-voi/internal/toolchain/constraints.go:48:6: undefined: __SOFTWARE_REQUIRES_GO_VERSION_1_18__

    package main

    import ( "fmt"

    "github.com/denisbrodbeck/machineid"
    "github.com/keygen-sh/keygen-go"
    

    )

    func main() { keygen.Account = "YOUR_KEYGEN_ACCOUNT_ID" keygen.Product = "YOUR_KEYGEN_PRODUCT_ID" keygen.LicenseKey = "key/..."

    fingerprint, err := machineid.ProtectedID(keygen.Product)
    if err != nil {
    	panic(err)
    }
    
    // Validate the license for the current fingerprint
    license, err := keygen.Validate(fingerprint)
    switch {
    case err == keygen.ErrLicenseNotActivated:
    	// Activate the current fingerprint
    	machine, err := license.Activate(fingerprint)
    	switch {
    	case err == keygen.ErrMachineLimitExceeded:
    		panic("machine limit has been exceeded!")
    	case err != nil:
    		panic("machine activation failed!")
    	}
    case err == keygen.ErrLicenseExpired:
    	panic("license is expired!")
    case err != nil:
    	panic("license is invalid!")
    }
    
    fmt.Println("License is activated!")
    

    }

A go sdk for baidu netdisk open platform 百度网盘开放平台 Go SDK

Pan Go Sdk 该代码库为百度网盘开放平台Go语言的SDK

Nov 22, 2022
Nextengine-sdk-go: the NextEngine SDK for the Go programming language

NextEngine SDK for Go nextengine-sdk-go is the NextEngine SDK for the Go programming language. Getting Started Install go get github.com/takaaki-s/nex

Dec 7, 2021
Commercetools-go-sdk is fork of original commercetools-go-sdk

commercetools-go-sdk The Commercetools Go SDK is automatically generated based on the official API specifications of Commercetools. It should therefor

Dec 13, 2021
Sdk-go - Go version of the Synapse SDK

synapsesdk-go Synapse Protocol's Go SDK. Currently in super duper alpha, do not

Jan 7, 2022
Redash-go-sdk - An SDK for the programmatic management of Redash, in Go
Redash-go-sdk - An SDK for the programmatic management of Redash, in Go

Redash Go SDK An SDK for the programmatic management of Redash. The main compone

Dec 13, 2022
A cross platform desktop service that watches custom folders for file changes and updates the corresponding database in Notion.

A cross platform desktop service that watches custom folders for file changes and updates the corresponding database in Notion. Perfect for tracking reading lists

Mar 12, 2022
Updates labels for a Github repository using a template file.

Github Labeler The purpose of this application is to sync your default labels with a repository hosted by Github. Labeler automatically merges your la

Mar 6, 2022
Serverless SOAR (Security Orchestration, Automation and Response) framework for automatic inspection and evaluation of security alert
Serverless SOAR (Security Orchestration, Automation and Response) framework for automatic inspection and evaluation of security alert

DeepAlert DeepAlert is a serverless framework for automatic response of security alert. Overview DeepAlert receives a security alert that is event of

Jan 3, 2023
AWS credential_process utility to assume AWS IAM Roles with Yubikey Touch and Authenticator App TOPT MFA to provide temporary session credentials; With encrypted caching and support for automatic credential refresh.
AWS credential_process utility to assume AWS IAM Roles with Yubikey Touch and Authenticator App TOPT MFA to provide temporary session credentials; With encrypted caching and support for automatic credential refresh.

AWS credential_process utility to assume AWS IAM Roles with Yubikey Touch and Authenticator App TOPT MFA to provide temporary session credentials; With encrypted caching and support for automatic credential refresh.

Dec 20, 2022
📼 Automatic Twitch Recorder

?? rekōdā - Automatic Twitch Recorder Rekōdā, レコダ - means Recorder in Japanese Is a CLI tool inspired by streamlink but with more capabilities. Mainly

Dec 7, 2022