sampler-fork/metadata/license.go

50 lines
811 B
Go
Raw Normal View History

2019-05-24 02:58:46 +00:00
package metadata
import (
"gopkg.in/yaml.v2"
"log"
)
type License struct {
Purchased bool
Valid bool
Key *string
Username *string
Company *string
}
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 InitLicense() {
license := License{
Purchased: false,
Valid: false,
}
file, err := yaml.Marshal(license)
if err != nil {
2019-05-20 04:14:13 +00:00
log.Fatalf("Failed to marshal config file: %v", err)
}
initStorage()
saveStorageFile(file, getPlatformStoragePath(licenseFileName))
}