mirror of
				https://github.com/mickael-kerjean/filestash.git
				synced 2025-11-04 13:35:46 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			36 lines
		
	
	
		
			507 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			36 lines
		
	
	
		
			507 B
		
	
	
	
		
			Go
		
	
	
	
	
	
package common
 | 
						|
 | 
						|
import (
 | 
						|
	"time"
 | 
						|
)
 | 
						|
 | 
						|
const (
 | 
						|
	ADMIN_CLAIM = "ADMIN"
 | 
						|
)
 | 
						|
 | 
						|
type AdminToken struct {
 | 
						|
	Claim  string     `json:"token"`
 | 
						|
	Expire time.Time  `json:"time"`
 | 
						|
}
 | 
						|
 | 
						|
func NewAdminToken() AdminToken {
 | 
						|
	return AdminToken{
 | 
						|
		Claim: ADMIN_CLAIM,
 | 
						|
		Expire: time.Now().Add(time.Hour * 24),
 | 
						|
	}
 | 
						|
}
 | 
						|
 | 
						|
func (this AdminToken) IsAdmin() bool {
 | 
						|
	if this.Claim != ADMIN_CLAIM {
 | 
						|
		return false
 | 
						|
	}
 | 
						|
	return true
 | 
						|
}
 | 
						|
 | 
						|
func (this AdminToken) IsValid() bool {
 | 
						|
	if this.Expire.Sub(time.Now()) <= 0 {
 | 
						|
		return false
 | 
						|
	}
 | 
						|
	return true
 | 
						|
}
 |