sampler-fork/metadata/license.go

43 lines
750 B
Go
Raw Normal View History

2019-05-24 02:58:46 +00:00
package metadata
import (
2019-06-21 04:45:32 +00:00
"gopkg.in/yaml.v3"
"log"
)
type License struct {
Key *string `yaml:"k"`
Username *string `yaml:"u"`
Company *string `yaml:"c"`
Valid bool `yaml:"v"`
}
const licenseFileName = "license.yml"
func GetLicense() *License {
if !fileExists(licenseFileName) {
return nil
} else {
file := readStorageFile(getPlatformStoragePath(licenseFileName))
license := new(License)
err := yaml.Unmarshal(file, license)
if err != nil {
2019-05-20 04:14:13 +00:00
log.Fatalf("Failed to read license file: %v", err)
}
return license
}
}
func SaveLicense(license License) {
file, err := yaml.Marshal(license)
if err != nil {
log.Fatalf("Failed to marshal license file: %v", err)
}
saveStorageFile(file, licenseFileName)
}