1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-07-24 07:39:43 +02:00

license code refactoring

This commit is contained in:
Harvey Kandola 2017-02-23 10:29:51 -08:00
parent 3f87401d49
commit edccb39019
5 changed files with 22 additions and 40 deletions

View file

@ -11,8 +11,10 @@
package core
import "fmt"
import "time"
import (
"fmt"
"time"
)
// ProdInfo describes a product
type ProdInfo struct {
@ -25,19 +27,6 @@ type ProdInfo struct {
License License
}
// Product returns product edition details
func Product() (p ProdInfo) {
p.Major = "0"
p.Minor = "42"
p.Patch = "0"
p.Version = fmt.Sprintf("%s.%s.%s", p.Major, p.Minor, p.Patch)
p.Edition = "Community"
p.Title = fmt.Sprintf("%s Edition", p.Edition)
p.License = License{}
return
}
// License holds details of product license.
type License struct {
Name string `json:"name"`
@ -47,6 +36,7 @@ type License struct {
End time.Time `json:"end"`
Seats int `json:"seats"`
Trial bool `json:"trial"`
Valid bool
}
// IsEmpty determines if we have a license.
@ -54,17 +44,6 @@ func (l *License) IsEmpty() bool {
return l.Seats == 0 && len(l.Name) == 0 && len(l.Email) == 0 && l.Start.Year() == 1 && l.End.Year() == 1
}
// IsValid determines if we have populated and valid license.
// An empty license is valid.
func (l *License) IsValid() bool {
if l.IsEmpty() {
return true
}
now := time.Now().UTC()
return l.End.Day() <= now.Day() && l.End.Month() <= now.Month() && l.End.Year() <= now.Year()
}
// Status returns formatted message stating if license is empty/populated and invalid/valid.
func (l *License) Status() string {
lp := "populated"
@ -72,7 +51,7 @@ func (l *License) Status() string {
lp = "empty"
}
lv := "invalid"
if l.IsValid() {
if l.Valid {
lv = "valid"
}