persistence

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2023 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	RuleSetPersistence   = newFactoryPersistence[RuleSet]()
	CardPersistence      = newFactoryPersistence[Card]()
	CharacterPersistence = newFactoryPersistence[Character]()
	SkillPersistence     = newFactoryPersistence[Skill]()
	SummonPersistence    = newFactoryPersistence[Summon]()
	EventPersistence     = newFactoryPersistence[Event]()

	LocalizationPersistence = newMemoryCache[string, localization.LanguagePack]()
	ModInfoPersistence      = newMemoryCache[string, ModInfo]()
	RoomInfoPersistence     = newMemoryCache[uint64, RoomInfo]()

	TokenPersistence = newTimingMemoryCache[string, Token]()

	CardDeckPersistence DatabasePersistence[uint64, CardDeck]
	PlayerPersistence   DatabasePersistence[uint64, Player]
)

Functions

func Load

func Load(errChan chan error)

Load 从持久化文件读取信息,写入持久化模块

func NewCardPersistenceAdapter

func NewCardPersistenceAdapter() adapter.Adapter[model.Card, Card]

func NewEventPersistenceAdapter

func NewEventPersistenceAdapter() adapter.Adapter[model.Event, Event]

func NewRuleSetAdapter

func NewRuleSetAdapter() adapter.Adapter[model.RuleSet, RuleSet]

func NewSkillPersistenceAdapter

func NewSkillPersistenceAdapter() adapter.Adapter[model.Skill, Skill]

func Quit

func Quit()

Quit 退出持久化模块的各种持久化服务

func Serve

func Serve(flushFeq time.Duration, errChan chan error)

Serve 开启持久化模块的服务

func SetStoragePath

func SetStoragePath(path string) error

SetStoragePath 设置持久化文件的存放位置

Types

type Cacheable

type Cacheable interface {
	ID() uint64
}

type Card

type Card struct {
	Cacheable
	Card model.Card
}

Card 被持久化模块托管的Card工厂的产品

type CardDeck

type CardDeck struct {
	ID               uint64   `xorm:"pk autoincr notnull unique index" json:"id"` // ID CardDeck的记录ID,主键
	OwnerUID         uint64   `xorm:"notnull index" json:"owner_uid"`             // OwnerUID CardDeck的持有者
	RequiredPackages []string `xorm:"notnull json" json:"required_packages"`      // RequiredPackages CardDeck需要的包
	Cards            []uint64 `xorm:"notnull json" json:"cards"`                  // Cards CardDeck包含的卡组
	Characters       []uint64 `xorm:"notnull json" json:"characters"`             // Characters CardDeck包含的角色
}

CardDeck 被持久化模块托管的CardDeck信息

type CardPersistenceAdapter

type CardPersistenceAdapter struct{}

func (CardPersistenceAdapter) Convert

func (c CardPersistenceAdapter) Convert(source model.Card) (success bool, result Card)

type Character

type Character struct {
	Cacheable
	TypeID      uint64
	Affiliation enum.Affiliation
	Vision      enum.ElementType
	Weapon      enum.WeaponType
	MaxHP       uint
	MaxMP       uint
	Skills      []uint64
}

Character 被持久化模块托管的CharacterInfo工厂的产品

func (Character) ID

func (c Character) ID() uint64

type DatabasePersistence

type DatabasePersistence[PK Increasable, T any] interface {
	QueryByID(id PK) (has bool, result T)
	UpdateByID(id PK, newEntity T) (success bool)
	InsertOne(entity *T) (success bool, result *T)
	DeleteOne(id PK) (success bool)
	FindOne(condition T) (has bool, result T)
	Find(condition T) (results []T)
}

DatabasePersistence 数据库持久化

type Event

type Event struct {
	Cacheable
	Event model.Event
}

Event 被持久化模块托管的Event工厂的产品

type EventPersistenceAdapter

type EventPersistenceAdapter struct{}

func (EventPersistenceAdapter) Convert

func (e EventPersistenceAdapter) Convert(source model.Event) (success bool, result Event)

type Factory

type Factory[entity any] interface {
	Ctor() func() entity
	Enable() bool
	ID() uint64
	UID() string
	// contains filtered or unexported methods
}

Factory 可持久化的实体接口,本质是一个生产entity的工厂

func NewFactory

func NewFactory[entity any](id uint64, uid string) Factory[entity]

type FactoryPersistence

type FactoryPersistence[T any] interface {
	Serve(flushFrequency time.Duration, flushPath, flushFile string, errChan chan error)
	Exit()
	Load(filePath string) (err error)
	QueryByID(id uint64) (has bool, result Factory[T])
	QueryByUID(uid string) (has bool, result Factory[T])
	Register(ctor func() T) (success bool)
	Flush(flushPath string, flushFile string) (err error)
}

FactoryPersistence 持久化接口,抽象工厂集合的持久化封装

type FactoryPersistenceRecord

type FactoryPersistenceRecord struct {
	ID  uint64 `json:"id"`
	UID string `json:"uid"`
}

FactoryPersistenceRecord 抽象工厂的持久化结构记录

type Increasable

type Increasable interface {
	int | uint | byte | rune | int8 | int16 | int64 | uint16 | uint32 | uint64
}

Increasable 可增长的,用于数据库主键

type MemoryCache

type MemoryCache[PK comparable, T any] interface {
	QueryByID(id PK) (has bool, result T)
	UpdateByID(id PK, newEntity T) (success bool)
	InsertOne(id PK, entity T) (success bool)
	DeleteOne(id PK) (success bool)
}

MemoryCache 内存缓存,不进行持久化

type ModInfo

type ModInfo struct {
	PackageName string `json:"package_name"`
	Events      []uint `json:"events"`
	Characters  []uint `json:"characters"`
	Cards       []uint `json:"cards"`
	Skills      []uint `json:"skills"`
	Summons     []uint `json:"summons"`
}

ModInfo 被持久化模块托管的ModInfo缓存

type Player

type Player struct {
	UID      uint64 `xorm:"pk autoincr notnull unique index"` // UID Player的UID,主键
	NickName string `xorm:"notnull varchar(64)"`              // NickName Player的昵称
	Password string `xorm:"notnull varchar(64)"`              // Password Player的密码Hash
}

Player 被持久化模块托管的Player信息

type RoomInfo

type RoomInfo struct {
	RoomID           uint64              `json:"room_id"`
	CreatedAt        time.Time           `json:"created_at"`
	CreatorID        uint64              `json:"creator_id"`
	Token            string              `json:"token"`
	Players          []uint64            `json:"players"`
	Viewers          uint64              `json:"viewers"`
	RequiredPackages []string            `json:"required_packages"`
	GameOptions      message.GameOptions `json:"game_options"`
}

RoomInfo 被持久化模块托管的RoomInfo缓存

type RuleSet

type RuleSet struct {
	Cacheable
	Rule model.RuleSet
}

RuleSet 被持久化模块托管的RuleSet工厂的产品

type RuleSetPersistenceAdapter

type RuleSetPersistenceAdapter struct{}

func (RuleSetPersistenceAdapter) Convert

func (r RuleSetPersistenceAdapter) Convert(source model.RuleSet) (success bool, result RuleSet)

type Skill

type Skill struct {
	Cacheable
	Skill model.Skill
}

Skill 被持久化模块托管的Skill工厂的产品

type SkillPersistenceAdapter

type SkillPersistenceAdapter struct{}

func (SkillPersistenceAdapter) Convert

func (s SkillPersistenceAdapter) Convert(source model.Skill) (success bool, result Skill)

type Summon

type Summon struct {
	Cacheable
}

Summon 被持久化模块托管的Summon工厂的产品

type TimingMemoryCache

type TimingMemoryCache[PK comparable, T any] interface {
	QueryByID(id PK) (has bool, result T, timeoutAt time.Time)
	UpdateByID(id PK, entity T) (success bool, timeoutAt time.Time)
	RefreshByID(id PK, timeout time.Duration) (success bool, timeoutAt time.Time)
	InsertOne(id PK, entity T, timeout time.Duration) (success bool, timeoutAt time.Time)
	DeleteByID(id PK) (success bool)
	Serve(proactivelyCleanTime time.Duration, proactivelyCleanIndex float64)
	Exit()
}

TimingMemoryCache 带超时系统的内存缓存,不进行持久化,类redis

type Token

type Token struct {
	UID uint64 // UID Token持有者的UID
	ID  string // ID Token的ID
}

Token 被持久化模块托管的Token缓存

Jump to

Keyboard shortcuts

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