You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

location.go 827 B

123456789101112131415161718192021222324252627282930313233343536
  1. package db
  2. import (
  3. "fmt"
  4. cortypes "gitlink.org.cn/cloudream/jcs-pub/coordinator/types"
  5. )
  6. type LocationDB struct {
  7. *DB
  8. }
  9. func (db *DB) Location() *LocationDB {
  10. return &LocationDB{DB: db}
  11. }
  12. func (*LocationDB) GetByID(ctx SQLContext, id int64) (cortypes.Location, error) {
  13. var ret cortypes.Location
  14. err := ctx.First(&ret, id).Error
  15. return ret, err
  16. }
  17. func (db *LocationDB) FindLocationByExternalIP(ctx SQLContext, ip string) (cortypes.Location, error) {
  18. var locID int64
  19. err := ctx.Table("Hub").Select("LocationID").Where("ExternalIP = ?", ip).Scan(&locID).Error
  20. if err != nil {
  21. return cortypes.Location{}, fmt.Errorf("finding hub by external ip: %w", err)
  22. }
  23. loc, err := db.GetByID(ctx, locID)
  24. if err != nil {
  25. return cortypes.Location{}, fmt.Errorf("getting location by id: %w", err)
  26. }
  27. return loc, nil
  28. }

本项目旨在将云际存储公共基础设施化,使个人及企业可低门槛使用高效的云际存储服务(安装开箱即用云际存储客户端即可,无需关注其他组件的部署),同时支持用户灵活便捷定制云际存储的功能细节。