api_key.go 718 B

1234567891011121314151617181920212223242526272829303132
  1. // SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
  2. // SPDX-License-Identifier: Apache-2.0
  3. package model // import "miniflux.app/v2/internal/model"
  4. import (
  5. "time"
  6. "miniflux.app/v2/internal/crypto"
  7. )
  8. // APIKey represents an application API key.
  9. type APIKey struct {
  10. ID int64
  11. UserID int64
  12. Token string
  13. Description string
  14. LastUsedAt *time.Time
  15. CreatedAt time.Time
  16. }
  17. // NewAPIKey initializes a new APIKey.
  18. func NewAPIKey(userID int64, description string) *APIKey {
  19. return &APIKey{
  20. UserID: userID,
  21. Token: crypto.GenerateRandomString(32),
  22. Description: description,
  23. }
  24. }
  25. // APIKeys represents a collection of API Key.
  26. type APIKeys []*APIKey