go unipdf
unipdf
internal/license/license.go:
package license
import (
"fmt"
"time"
"github.com/unidoc/unipdf/v3/common"
)
func (licenseKey *LicenseKey) ToString() string {
if licenseKey.meteredSubscription {
return `Metered subscription`
}
result := fmt.Sprintf("License Id: %s\n", licenseKey.LicenseId)
result += fmt.Sprintf("Customer Id: %s\n", licenseKey.CustomerId)
result += fmt.Sprintf("Customer Name: %s\n", licenseKey.CustomerName)
result += fmt.Sprintf("Tier: %s\n", licenseKey.Tier)
result += fmt.Sprintf("Created At: %s\n", common.UtcTimeFormat(licenseKey.CreatedAt))
if licenseKey.ExpiresAt == nil {
result += "Expires At: Never\n"
} else {
result += fmt.Sprintf("Expires At: %s\n", common.UtcTimeFormat(*licenseKey.ExpiresAt))
}
result += fmt.Sprintf("Creator: %s <%s>\n", licenseKey.CreatorName, licenseKey.CreatorEmail)
return result
}
func GetMeteredState() (MeteredStatus, error) {
state := MeteredStatus{OK: true, Credits: 999, Used: 0}
return state, nil
}
type LicenseKey struct {
LicenseId string `json:"license_id"`
CustomerId string `json:"customer_id"`
CustomerName string `json:"customer_name"`
Tier string `json:"tier"`
CreatedAt time.Time `json:"-"`
CreatedAtInt int64 `json:"created_at"`
ExpiresAt *time.Time `json:"-"`
ExpiresAtInt int64 `json:"expires_at"`
CreatedBy string `json:"created_by"`
CreatorName string `json:"creator_name"`
CreatorEmail string `json:"creator_email"`
UniPDF bool `json:"unipdf"`
UniOffice bool `json:"unioffice"`
UniHTML bool `json:"unihtml"`
Trial bool `json:"trial"`
meteredSubscription bool // Metered Subscription
apiKey string
persistent bool
usageLog bool
}
func SetMeteredKey(apiKey string) error {
licenseKey := &LicenseKey{meteredSubscription: true, apiKey: apiKey, persistent: true}
defaultLicenseKey = licenseKey
return nil
}
type MeteredStatus struct {
OK bool
Credits int64
Used int64
}
func SetMeteredKeyUsageLogVerboseMode(val bool) { defaultLicenseKey.usageLog = val }
func (licenseKey *LicenseKey) Validate() error {
return nil
}
func TrackUse(useKey string) {
}
var defaultLicenseKey = MakeUnlicensedKey()
func Track(docKey string, useKey string, docName string) error {
return nil
}
func SetMeteredKeyPersistentCache(val bool) { defaultLicenseKey.persistent = val }
func (licenseKey *LicenseKey) IsLicensed() bool {
return true
}
func MakeUnlicensedKey() *LicenseKey {
lincese := LicenseKey{}
lincese.CustomerName = "Licensed"
lincese.Tier = LicenseTierBusiness
lincese.CreatedAt = time.Now().UTC()
lincese.CreatedAtInt = lincese.CreatedAt.Unix()
return &lincese
}
func init() {
defaultLicenseKey = MakeUnlicensedKey()
}
func SetLicenseKey(content string, customerName string) error {
return nil
}
func GetLicenseKey() *LicenseKey {
return defaultLicenseKey
}
const (
LicenseTierUnlicensed = "unlicensed"
LicenseTierCommunity = "community"
LicenseTierIndividual = "individual"
LicenseTierBusiness = "business"
)
func (licenseKey *LicenseKey) TypeToString() string {
if licenseKey.meteredSubscription {
return "Metered subscription"
}
if licenseKey.Tier == LicenseTierUnlicensed {
return "Unlicensed"
}
if licenseKey.Tier == LicenseTierCommunity {
return "AGPLv3 Open Source Community License"
}
if licenseKey.Tier == LicenseTierIndividual || licenseKey.Tier == "indie" {
return "Commercial License - Individual"
}
return "Commercial License - Business"
}

浙公网安备 33010602011771号