persistence

package
v0.0.0-...-6d513be Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 2, 2024 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrorNetworkNotFound          = errors.New("network not found")
	ErrorNetworkExists            = errors.New("network already exists")
	ErrorAddressNotInCIDRRange    = errors.New("address is not within network CIDR range")
	ErrorAddressAlreadyAllocated  = errors.New("address already allocated")
	ErrorAddressNotFoundInUsedIPs = errors.New("address not found in used IPs")
	ErrorCIDRInUse                = errors.New("cidr already in use")
	ErrNoAvailableIP              = errors.New("no available IP addresses in the network")
)
View Source
var ErrorHostNotFound = errors.New("host not found")

Functions

func ConnectMongoDB

func ConnectMongoDB(uri string) (*mongo.Client, error)

func ToFindOptions

func ToFindOptions(listOptions *entity.HostFindOptions) *options.FindOptions

Types

type FindOptions

type FindOptions struct {
	Filters map[string]interface{}
	Sort    map[string]int // 1 for ascending, -1 for descending
	Limit   int
	Offset  int
}

type HostMongodbRepository

type HostMongodbRepository struct {
	// contains filtered or unexported fields
}

func NewHostMongodbRepository

func NewHostMongodbRepository(client *mongo.Client, dbName string) *HostMongodbRepository

func (*HostMongodbRepository) AddHostRule

func (h *HostMongodbRepository) AddHostRule(ctx context.Context, hostID string, ruleIDs ...string) error

func (*HostMongodbRepository) Create

func (h *HostMongodbRepository) Create(ctx context.Context, host *entity.Host) (*entity.Host, error)

func (*HostMongodbRepository) Delete

func (h *HostMongodbRepository) Delete(ctx context.Context, id string) error

func (*HostMongodbRepository) DeleteHostRule

func (h *HostMongodbRepository) DeleteHostRule(ctx context.Context, hostID string, ruleID ...string) error

func (*HostMongodbRepository) EnrollHost

func (h *HostMongodbRepository) EnrollHost(ctx context.Context, enrollHost *entity.EnrollHost) error

func (*HostMongodbRepository) Find

func (*HostMongodbRepository) Get

func (*HostMongodbRepository) GetEnrollHost

func (h *HostMongodbRepository) GetEnrollHost(ctx context.Context, getEnrollHost *entity.GetEnrollHost) (*entity.EnrollHost, error)

func (*HostMongodbRepository) GetHostByEnrollCode

func (h *HostMongodbRepository) GetHostByEnrollCode(ctx context.Context, code string) (*entity.Host, error)

func (*HostMongodbRepository) HostOffline

func (h *HostMongodbRepository) HostOffline(ctx context.Context, hostOffline *entity.HostOffline) (*entity.HostOffline, error)

func (*HostMongodbRepository) HostOnline

func (h *HostMongodbRepository) HostOnline(ctx context.Context, hostOnline *entity.HostOnline) (*entity.HostOnline, error)

func (*HostMongodbRepository) ListHostRule

func (*HostMongodbRepository) Update

func (h *HostMongodbRepository) Update(ctx context.Context, host *entity.Host) (*entity.Host, error)

type MongoDBRepository

type MongoDBRepository struct {
	// contains filtered or unexported fields
}

func NewNetworkMongoDBRepository

func NewNetworkMongoDBRepository(client *mongo.Client, dbName string) *MongoDBRepository

func (*MongoDBRepository) AllocateIP

func (m *MongoDBRepository) AllocateIP(ctx context.Context, id string, ip string) error

func (*MongoDBRepository) AutoAllocateIP

func (m *MongoDBRepository) AutoAllocateIP(ctx context.Context, id string) (string, error)

func (*MongoDBRepository) AvailableIPs

func (m *MongoDBRepository) AvailableIPs(ctx context.Context, id string) ([]string, error)

func (*MongoDBRepository) Create

func (m *MongoDBRepository) Create(ctx context.Context, network *entity.Network) (*entity.Network, error)

func (*MongoDBRepository) Delete

func (m *MongoDBRepository) Delete(ctx context.Context, id string) error

func (*MongoDBRepository) Find

func (*MongoDBRepository) Get

func (*MongoDBRepository) ReleaseIP

func (m *MongoDBRepository) ReleaseIP(ctx context.Context, id string, ip string) error

func (*MongoDBRepository) Update

func (*MongoDBRepository) UsedIPs

func (m *MongoDBRepository) UsedIPs(ctx context.Context, id string) ([]string, error)

type NetWorkModel

type NetWorkModel struct {
	ID        string `json:"id"`
	Name      string `json:"name"`
	Cidr      string `json:"cidr"`
	Status    uint   `gorm:"comment:网络状态(0=正常状态, 1=锁定状态, 2=删除状态)"`
	CreatedAt int64  `gorm:"autoCreateTime;comment:创建时间"`
	UpdatedAt int64  `gorm:"autoUpdateTime;comment:更新时间"`
	DeletedAt int64  `gorm:"default:0;comment:删除时间"`

	UsedIPs      []string // 存储分配的地址
	AvailableIPs []string // 存储可用的地址
}

func (*NetWorkModel) From

func (m *NetWorkModel) From(e *entity.Network) error

func (*NetWorkModel) To

func (m *NetWorkModel) To() (*entity.Network, error)

type NetworkMemoryRepository

type NetworkMemoryRepository struct {
	// contains filtered or unexported fields
}

func NewNetworkMemoryRepository

func NewNetworkMemoryRepository() *NetworkMemoryRepository

func (*NetworkMemoryRepository) AllocateIP

func (m *NetworkMemoryRepository) AllocateIP(ctx context.Context, id string, ip string) error

func (*NetworkMemoryRepository) AutoAllocateIP

func (m *NetworkMemoryRepository) AutoAllocateIP(ctx context.Context, id string) (string, error)

func (*NetworkMemoryRepository) AvailableIPs

func (m *NetworkMemoryRepository) AvailableIPs(ctx context.Context, id string) ([]string, error)

func (*NetworkMemoryRepository) Create

func (*NetworkMemoryRepository) Delete

func (m *NetworkMemoryRepository) Delete(ctx context.Context, id string) error

func (*NetworkMemoryRepository) Find

func (*NetworkMemoryRepository) Get

func (*NetworkMemoryRepository) ReleaseIP

func (m *NetworkMemoryRepository) ReleaseIP(ctx context.Context, id string, ip string) error

func (*NetworkMemoryRepository) Update

func (*NetworkMemoryRepository) UsedIPs

func (m *NetworkMemoryRepository) UsedIPs(ctx context.Context, id string) ([]string, error)

type Repositories

type Repositories struct {
	HostRepo     repository.HostRepository
	RuleRepo     repository.RuleRepository
	HostRuleRepo repository.HostRuleRepository
	NetworkRepo  networkRepo.NetworkRepository
	// contains filtered or unexported fields
}

func NewRepositories

func NewRepositories(client *mongo.Client, dbName string) *Repositories

func (*Repositories) Automigrate

func (r *Repositories) Automigrate() error

func (*Repositories) TXRepositories

func (r *Repositories) TXRepositories(ctx context.Context, fc func(txr *Repositories, sessionCtx mongo.SessionContext) error) error

type RuleMongodbRepository

type RuleMongodbRepository struct {
	// contains filtered or unexported fields
}

func NewRuleMongodbRepository

func NewRuleMongodbRepository(client *mongo.Client, dbName string) *RuleMongodbRepository

func (*RuleMongodbRepository) Create

func (m *RuleMongodbRepository) Create(ctx context.Context, userID string, rule *entity.Rule) (*entity.Rule, error)

func (*RuleMongodbRepository) Delete

func (m *RuleMongodbRepository) Delete(ctx context.Context, id string) error

func (*RuleMongodbRepository) Find

func (m *RuleMongodbRepository) Find(ctx context.Context, userID string, options *entity.RuleFindOptions) ([]*entity.Rule, error)

func (*RuleMongodbRepository) Get

func (m *RuleMongodbRepository) Get(ctx context.Context, userID, id string) (*entity.Rule, error)

func (*RuleMongodbRepository) Gets

func (m *RuleMongodbRepository) Gets(ctx context.Context, userID string, ids []string) ([]*entity.Rule, error)

func (*RuleMongodbRepository) Update

func (m *RuleMongodbRepository) Update(ctx context.Context, userID string, rule *entity.Rule) error

type UserMongodbRepository

type UserMongodbRepository struct {
	// contains filtered or unexported fields
}

func NewUserMongodbRepository

func NewUserMongodbRepository(client *mongo.Client, dbName string) *UserMongodbRepository

func (*UserMongodbRepository) Create

func (m *UserMongodbRepository) Create(ctx context.Context, user *entity.User) (*entity.User, error)

func (*UserMongodbRepository) Delete

func (m *UserMongodbRepository) Delete(ctx context.Context, id string) error

func (*UserMongodbRepository) Find

func (m *UserMongodbRepository) Find(ctx context.Context, options *entity.FindOptions) ([]*entity.User, error)

func (*UserMongodbRepository) Get

func (*UserMongodbRepository) Update

func (m *UserMongodbRepository) Update(ctx context.Context, user *entity.User) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL