47 lines
952 B
Go
Raw Normal View History

2017-07-08 22:00:11 +00:00
/*
* This file is subject to the terms and conditions defined in
* file 'LICENSE.md', which is part of this source code package.
*/
2018-08-03 10:18:53 +00:00
// Package license helps manage commercial licenses and check if they are valid for the version of unidoc used.
2017-07-08 22:00:11 +00:00
package license
import (
"fmt"
"strings"
)
2017-07-08 22:00:11 +00:00
// Defaults to the open source license.
2018-02-23 14:07:26 +00:00
var licenseKey *LicenseKey = MakeUnlicensedKey()
2017-07-08 22:00:11 +00:00
// Sets and validates the license key.
func SetLicenseKey(content string, customerName string) error {
2017-07-08 22:00:11 +00:00
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)
}
2017-07-08 22:00:11 +00:00
err = lk.Validate()
if err != nil {
return err
}
licenseKey = &lk
return nil
}
func GetLicenseKey() *LicenseKey {
2018-02-23 14:07:26 +00:00
if licenseKey == nil {
return nil
}
// Copy.
lk2 := *licenseKey
return &lk2
2017-07-08 22:00:11 +00:00
}