Alfred Hall de4548fc61 Adding customerName parameter to SetLicenseKey
This is to make the license information more verbose. Breaking change.
2018-08-16 17:10:53 +00:00

47 lines
952 B
Go

/*
* This file is subject to the terms and conditions defined in
* file 'LICENSE.md', which is part of this source code package.
*/
// Package license helps manage commercial licenses and check if they are valid for the version of unidoc used.
package license
import (
"fmt"
"strings"
)
// Defaults to the open source license.
var licenseKey *LicenseKey = MakeUnlicensedKey()
// Sets and validates the license key.
func SetLicenseKey(content string, customerName string) error {
lk, err := licenseKeyDecode(content)
if err != nil {
return err
}
if strings.ToLower(lk.CustomerName) != strings.ToLower(customerName) {
return fmt.Errorf("Customer name mismatch, expected '%s', but got '%s'", customerName, lk.CustomerName)
}
err = lk.Validate()
if err != nil {
return err
}
licenseKey = &lk
return nil
}
func GetLicenseKey() *LicenseKey {
if licenseKey == nil {
return nil
}
// Copy.
lk2 := *licenseKey
return &lk2
}