api_key.go 741 B

123456789101112131415161718192021222324252627282930313233
  1. // Copyright 2020 Frédéric Guillot. All rights reserved.
  2. // Use of this source code is governed by the Apache 2.0
  3. // license that can be found in the LICENSE file.
  4. package model // import "miniflux.app/model"
  5. import (
  6. "time"
  7. "miniflux.app/crypto"
  8. )
  9. // APIKey represents an application API key.
  10. type APIKey struct {
  11. ID int64
  12. UserID int64
  13. Token string
  14. Description string
  15. LastUsedAt *time.Time
  16. CreatedAt time.Time
  17. }
  18. // NewAPIKey initializes a new APIKey.
  19. func NewAPIKey(userID int64, description string) *APIKey {
  20. return &APIKey{
  21. UserID: userID,
  22. Token: crypto.GenerateRandomString(32),
  23. Description: description,
  24. }
  25. }
  26. // APIKeys represents a collection of API Key.
  27. type APIKeys []*APIKey