model

package
v0.0.0-...-3c1c5df Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2025 License: GPL-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ModTypeBoth 双端类型模组
	ModTypeBoth = "both"
	// ModTypeClient 仅客户端类型模组
	ModTypeClient = "client"
)

模组类型常量

Variables

This section is empty.

Functions

func NewModInfoMapFromSlice

func NewModInfoMapFromSlice(list []*ModFile) (ModInfoMap, []*ModFile)

NewModInfoMapFromSlice 从一个模组对象切片中创建一个模组哈希表

  • list 模组对象列表切片

分别返回:

  • 包含原始列表的模组哈希表(已去除SHA256重复的)
  • 原始列表中重复的模组对象列表(即文件名不同但SHA256和其它某个文件相同的文件列表)

func ParseResultJson

func ParseResultJson[T any](resultData []byte) (T, error)

ParseResultJson 解析Result对象的JSON结果

  • resultData 结果对象的JSON数据

返回解析的内容结果

func PrintConfig

func PrintConfig(config any, prefix string)

PrintConfig 输出配置信息到控制台

  • config 打印的配置对象
  • prefix 递归前缀

func SetDefaultValue

func SetDefaultValue(object any)

SetDefaultValue 根据对象的default标签设定字段默认值

Types

type BaseConfig

type BaseConfig struct {
	// 模组文件夹位置
	// 服务端默认模组文件夹是当前运行路径下的mods
	// 客户端默认模组文件夹是当前运行路径下的.minecraft/mods
	ModFolder string `mapstructure:"mod-folder"`
}

BaseConfig 客户端与服务端的通用配置模型

type ClientConfig

type ClientConfig struct {
	// 基本通用配置
	Base BaseConfig `mapstructure:"base"`
	// 连接同步服务器配置
	Server struct {
		// 服务器地址
		Host string `mapstructure:"host"`
		// 服务器端口
		Port int `mapstructure:"port" default:"25566"`
	} `mapstructure:"server"`
	// 文件同步相关配置
	Sync struct {
		// 同时下载的文件数
		FetchConcurrency int `mapstructure:"fetch-concurrency" default:"3"`
		// 软删除
		// 若开启软删除,则在同步时删除本地模组文件时,不会实际对文件进行删除,而是移动到程序所在目录的mod-backup文件夹
		SoftRemove bool `mapstructure:"soft-remove" default:"true"`
		// 是否同步服务端配置的客户端辅助类型模组
		FetchClientMods bool `mapstructure:"fetch-client-mods" default:"false"`
		// 忽略同步的模组文件名列表
		// 默认情况下,若本地存在但服务器不存在的模组会被删除
		// 若某文件被加入到了忽略列表,则即使服务器不存在该文件也不会被删除
		IgnoreFileNames []string `mapstructure:"ignore-file-names"`
	} `mapstructure:"sync"`
	// 退出延迟,同步完成后延迟多少秒退出,若设为0则同步完成立即退出
	// 建议设定延迟几秒,以便于查看同步日志,排查错误
	ExitDelay int `mapstructure:"exit-delay" default:"2"`
}

ClientConfig 客户端配置

type ModFile

type ModFile struct {
	// 文件名
	Filename string `json:"filename"`
	// 文件SHA256摘要值
	Sha256 string `json:"sha256"`
	// 文件大小(字节)
	Size int64 `json:"size"`
	// 模组类型(双端或者客户端)
	Type string `json:"type"`
}

ModFile 模组文件信息

func NewModFile

func NewModFile(filepath, modType string) (*ModFile, error)

NewModFile 指定模组文件完整路径,读取并返回其模组文件信息对象

  • filepath 模组文件完整路径
  • modType 模组类型

返回模组文件信息

func NewModListFromFolder

func NewModListFromFolder(modFolder, modType string) ([]*ModFile, error)

NewModListFromFolder 从文件夹读取其中全部文件作为模组列表

  • modFolder 存放模组的文件夹
  • modType 模组类型

返回模组文件信息列表

type ModInfoMap

type ModInfoMap map[string]*ModFile

ModInfoMap 模组列表哈希表类型,其中:

  • 键:模组文件的SHA256摘要
  • 值:完整模组文件元数据

func (ModInfoMap) Contains

func (modMap ModInfoMap) Contains(mod *ModFile) bool

Contains 查看当前模组哈希表中是否存在某个模组

  • mod 要判断存在的模组对象

如果mod存在于当前modMap中,返回true,否则返回false

func (ModInfoMap) Remove

func (modMap ModInfoMap) Remove(removeMods ...*ModFile)

Remove 从modMap移除一些元素

  • removeMods 要移除的模组对象,为不定长参数

func (ModInfoMap) Subtract

func (modMap ModInfoMap) Subtract(subtractMap ModInfoMap) []*ModFile

Subtract 哈希表作差,查找出当前哈希表modMap存在但是传入哈希表subtractMap不存在的模组信息对象

  • subtractMap 传入的作差哈希表

返回当前哈希表modMap存在但是传入哈希表subtractMap不存在的 ModFile 对象指针切片

func (ModInfoMap) ToSlice

func (modMap ModInfoMap) ToSlice() []*ModFile

ToSlice 将模组哈希表转换成模组信息对象切片

返回切片形式的模组列表对象

type Result

type Result[T any] struct {
	// 操作是否成功
	Success bool `json:"success"`
	// 返回的消息
	Message string `json:"message,omitempty"`
	// 返回的数据,如果没有数据则为nil
	Data T `json:"data,omitempty"`
}

Result 统一的返回响应结果

func CreateFailedResult

func CreateFailedResult(message string) *Result[any]

CreateFailedResult 创建失败结果

func CreateNullSuccessResult

func CreateNullSuccessResult(message string) *Result[any]

CreateNullSuccessResult 创建不包含数据的成功结果

func CreateSuccessResult

func CreateSuccessResult[T any](message string, data T) *Result[T]

CreateSuccessResult 创建成功结果

type ServerConfig

type ServerConfig struct {
	// 基本通用配置
	Base BaseConfig `mapstructure:"base"`
	// 服务端口
	Port int `mapstructure:"port" default:"25566"`
	// 仅客户端辅助类型模组存放目录
	ClientModFolder string `mapstructure:"client-mods-folder" default:"client-mods"`
	// 守护进程模式运行时的配置
	Daemon struct {
		// 日志文件
		LogFile string `mapstructure:"log-file" default:"mc-sync-server.log"`
	} `mapstructure:"daemon"`
}

ServerConfig 服务端配置

Jump to

Keyboard shortcuts

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