wrapperr/modules/payload.go
Aune 787b00aebc File restructure
Different components moved to packages which are imported. More proper and clean compared to previous implementation.
2022-11-29 12:43:01 +01:00

26 lines
568 B
Go

package modules
import (
"aunefyren/wrapperr/models"
"time"
"github.com/google/uuid"
)
// NewPayload creates a new token payload with a specific username and duration
func NewPayload(username string, admin bool, authtoken string, duration time.Duration) (*models.Payload, error) {
tokenID, err := uuid.NewRandom()
if err != nil {
return nil, err
}
payload := &models.Payload{
ID: tokenID,
Username: username,
Admin: admin,
AuthToken: authtoken,
IssuedAt: time.Now(),
ExpiredAt: time.Now().Add(duration),
}
return payload, nil
}