sampler-fork/storage/license.go

50 lines
810 B
Go
Raw Normal View History

package storage
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))
}