2019-05-24 02:58:46 +00:00
|
|
|
package metadata
|
2019-05-20 04:12:40 +00:00
|
|
|
|
|
|
|
import (
|
2019-06-21 04:45:32 +00:00
|
|
|
"gopkg.in/yaml.v3"
|
2019-05-20 04:12:40 +00:00
|
|
|
"log"
|
|
|
|
)
|
|
|
|
|
|
|
|
type License struct {
|
2019-07-22 03:30:05 +00:00
|
|
|
Key *string `yaml:"k"`
|
|
|
|
Username *string `yaml:"u"`
|
|
|
|
Company *string `yaml:"c"`
|
|
|
|
Type *LicenseType `yaml:"t"`
|
|
|
|
Valid bool `yaml:"v"`
|
2019-05-20 04:12:40 +00:00
|
|
|
}
|
|
|
|
|
2019-07-22 03:30:05 +00:00
|
|
|
type LicenseType rune
|
|
|
|
|
|
|
|
const (
|
|
|
|
TypePersonal LicenseType = 0
|
|
|
|
TypeCommercial LicenseType = 1
|
|
|
|
)
|
|
|
|
|
2019-05-20 04:12:40 +00:00
|
|
|
const licenseFileName = "license.yml"
|
|
|
|
|
|
|
|
func GetLicense() *License {
|
2019-07-27 04:15:35 +00:00
|
|
|
|
2019-05-20 04:12:40 +00:00
|
|
|
if !fileExists(licenseFileName) {
|
|
|
|
return nil
|
2019-07-27 04:15:35 +00:00
|
|
|
}
|
2019-05-20 04:12:40 +00:00
|
|
|
|
2019-07-27 04:15:35 +00:00
|
|
|
file := readStorageFile(getPlatformStoragePath(licenseFileName))
|
2019-05-20 04:12:40 +00:00
|
|
|
|
2019-07-27 04:15:35 +00:00
|
|
|
license := new(License)
|
|
|
|
err := yaml.Unmarshal(file, license)
|
2019-05-20 04:12:40 +00:00
|
|
|
|
2019-07-27 04:15:35 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("Failed to read license file: %v", err)
|
2019-05-20 04:12:40 +00:00
|
|
|
}
|
2019-07-27 04:15:35 +00:00
|
|
|
|
|
|
|
return license
|
2019-05-20 04:12:40 +00:00
|
|
|
}
|
|
|
|
|
2019-05-28 01:44:06 +00:00
|
|
|
func SaveLicense(license License) {
|
2019-05-20 04:12:40 +00:00
|
|
|
|
|
|
|
file, err := yaml.Marshal(license)
|
|
|
|
if err != nil {
|
2019-05-28 01:44:06 +00:00
|
|
|
log.Fatalf("Failed to marshal license file: %v", err)
|
2019-05-20 04:12:40 +00:00
|
|
|
}
|
|
|
|
|
2019-05-28 01:44:06 +00:00
|
|
|
saveStorageFile(file, licenseFileName)
|
2019-05-20 04:12:40 +00:00
|
|
|
}
|