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 872 B

2 years ago
12345678910111213141516171819202122232425262728293031323334353637
  1. package db
  2. import (
  3. "fmt"
  4. "github.com/jmoiron/sqlx"
  5. "gitlink.org.cn/cloudream/storage/common/pkgs/db/model"
  6. )
  7. type LocationDB struct {
  8. *DB
  9. }
  10. func (db *DB) Location() *LocationDB {
  11. return &LocationDB{DB: db}
  12. }
  13. func (*LocationDB) GetByID(ctx SQLContext, id int64) (model.Location, error) {
  14. var ret model.Location
  15. err := sqlx.Get(ctx, &ret, "select * from Location where LocationID = ?", id)
  16. return ret, err
  17. }
  18. func (db *LocationDB) FindLocationByExternalIP(ctx SQLContext, ip string) (model.Location, error) {
  19. var locID int64
  20. err := sqlx.Get(ctx, &locID, "select LocationID from Node where ExternalIP = ?", ip)
  21. if err != nil {
  22. return model.Location{}, fmt.Errorf("finding node by external ip: %w", err)
  23. }
  24. loc, err := db.GetByID(ctx, locID)
  25. if err != nil {
  26. return model.Location{}, fmt.Errorf("getting location by id: %w", err)
  27. }
  28. return loc, nil
  29. }

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