login_sources.go 896 B

123456789101112131415161718192021222324252627282930313233343536
  1. // Copyright 2020 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package db
  5. import (
  6. "github.com/jinzhu/gorm"
  7. )
  8. // LoginSourcesStore is the persistent interface for login sources.
  9. //
  10. // NOTE: All methods are sorted in alphabetical order.
  11. type LoginSourcesStore interface {
  12. // GetByID returns the login source with given ID.
  13. // It returns ErrLoginSourceNotExist when not found.
  14. GetByID(id int64) (*LoginSource, error)
  15. }
  16. var LoginSources LoginSourcesStore
  17. type loginSources struct {
  18. *gorm.DB
  19. }
  20. func (db *loginSources) GetByID(id int64) (*LoginSource, error) {
  21. source := new(LoginSource)
  22. err := db.Where("id = ?", id).First(source).Error
  23. if err != nil {
  24. if err == gorm.ErrRecordNotFound {
  25. return localLoginSources.GetLoginSourceByID(id)
  26. }
  27. return nil, err
  28. }
  29. return source, nil
  30. }