Skip to main content

license.go

license.go - Overview

  1. Overview This file defines the data structures and related functions for handling licenses within the query service. It includes definitions for License, LicensePlan, Licenses, SubscriptionServerResp, Plan, LicenseDB, LicenseV3, CheckoutRequest, and PortalRequest along with functions for creating and converting LicenseV3 objects.

  2. Detailed Documentation

License

  • Purpose: Represents a license with its key, activation ID, plan details, parsed license details, feature set, validation message, and a flag indicating if it's the current license.
  • Parameters:
    • Key (string): The license key.
    • ActivationId (string): The activation ID associated with the license.
    • CreatedAt (time.Time): The time when the license was created.
    • PlanDetails (string): Encrypted plan information.
    • LicensePlan (LicensePlan): Parsed license details.
    • FeatureSet (basemodel.FeatureSet): The set of features enabled by the license.
    • ValidationMessage (string): A message indicating any validation errors.
    • IsCurrent (bool): Indicates whether this is the currently active license.
  • Returns: None

MarshalJSON

  • Purpose: Custom JSON marshaling for the License struct. It converts time.Time fields to Unix timestamps and only includes specific fields in the output.
  • Parameters: None
  • Returns:
    • []byte: JSON representation of the License struct.
    • error: An error, if any occurred during marshaling.

LicensePlan

  • Purpose: Represents the details of a license plan, including the plan key, valid from and until timestamps, and status.
  • Parameters:
    • PlanKey (string): The key identifying the license plan.
    • ValidFrom (int64): Unix timestamp indicating when the license is valid from.
    • ValidUntil (int64): Unix timestamp indicating when the license is valid until.
    • Status (string): The status of the license plan.
  • Returns: None

Licenses

  • Purpose: Represents a collection of licenses, along with trial and grace period information.
  • Parameters:
    • TrialStart (int64): Unix timestamp for the trial start date.
    • TrialEnd (int64): Unix timestamp for the trial end date.
    • OnTrial (bool): Indicates whether the account is currently on a trial.
    • WorkSpaceBlock (bool): Indicates whether the workspace is blocked.
    • TrialConvertedToSubscription (bool): Indicates whether the trial was converted to a subscription.
    • GracePeriodEnd (int64): Unix timestamp for the end of the grace period.
    • Licenses ([]License): A slice of License structs.
  • Returns: None

SubscriptionServerResp

  • Purpose: Represents the response from a subscription server, containing the status and license data.
  • Parameters:
    • Status (string): The status of the subscription.
    • Data (Licenses): The Licenses data.
  • Returns: None

Plan

  • Purpose: Represents a plan with a name.
  • Parameters:
    • Name (string): The name of the plan.
  • Returns: None

LicenseDB

  • Purpose: Represents a license stored in the database.
  • Parameters:
    • ID (string): The ID of the license.
    • Key (string): The license key.
    • Data (string): The license data.
  • Returns: None

LicenseV3

  • Purpose: Represents a new version of the license structure with a data map for flexible storage of license details and explicit fields for plan name, features, validity, and status.
  • Parameters:
    • ID (string): The ID of the license.
    • Key (string): The license key.
    • Data (map[string]interface<{}>): A map containing license data.
    • PlanName (string): The name of the license plan.
    • Features (basemodel.FeatureSet): The set of features enabled by the license.
    • Status (string): The status of the license.
    • IsCurrent (bool): Indicates whether this is the currently active license.
    • ValidFrom (int64): Unix timestamp indicating when the license is valid from.
    • ValidUntil (int64): Unix timestamp indicating when the license is valid until.
  • Returns: None

extractKeyFromMapStringInterface

  • Purpose: Extracts a value of type T from a map[string]interface<{}> given a key.
  • Parameters:
    • data (map[string]interface<{}>): The map to extract from.
    • key (string): The key to look for in the map.
  • Returns:
    • T: The value associated with the key, if found and of the correct type.
    • error: An error if the key is missing or the value is not of the expected type.

NewLicenseV3

  • Purpose: Creates a new LicenseV3 object from a map[string]interface<{}> containing license data. It extracts the ID, key, status, plan name and features and sets the plan name based on the status.
  • Parameters:
    • data (map[string]interface<{}>): A map containing the license data. Must contain "id", "key", "status" and "plan" keys. The "plan" key itself must be a map containing a "name" key.
  • Returns:
    • *LicenseV3: A pointer to the newly created LicenseV3 object.
    • error: An error if any required keys are missing or have incorrect types, or if marshaling/unmarshaling of features fails.

NewLicenseV3WithIDAndKey

  • Purpose: Creates a new LicenseV3 object with the provided ID and key, merging them into the provided data map.
  • Parameters:
    • id (string): The license ID.
    • key (string): The license key.
    • data (map[string]interface<{}>): A map containing the license data.
  • Returns:
    • *LicenseV3: A pointer to the newly created LicenseV3 object.
    • error: An error if the creation of the license fails.

ConvertLicenseV3ToLicenseV2

  • Purpose: Converts a LicenseV3 object to a License object (v2).
  • Parameters:
    • l (*LicenseV3): A pointer to the LicenseV3 object to convert.
  • Returns:
    • *License: A pointer to the converted License object.

CheckoutRequest

  • Purpose: Represents a request for a checkout session, including the success URL.
  • Parameters:
    • SuccessURL (string): The URL to redirect to upon successful checkout.
  • Returns: None

PortalRequest

  • Purpose: Represents a request to access a portal, including the success URL.
  • Parameters:
    • SuccessURL (string): The URL to redirect to upon successful access.
  • Returns: None
  1. Code Examples

Not applicable.

Include in Getting Started: NO