From 1030688f581c7ad9cc029cc5425c748f0846d4ea Mon Sep 17 00:00:00 2001 From: xmdhs Date: Mon, 9 Oct 2023 22:10:36 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=85=8D=E7=BD=AE=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E7=9A=84=E5=A4=A7=E5=B0=8F=E5=86=99=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/authlibskin/build.bat | 2 ++ cmd/authlibskin/config.yaml.template | 39 ++++++++++---------- cmd/authlibskin/main.go | 2 +- config/config.go | 44 +++++++++++------------ config/config.yaml | 53 ++++++++++++++++++++++++++++ config/yaml.go | 1 + config/yaml_test.go | 20 +++++++++++ 7 files changed, 118 insertions(+), 43 deletions(-) create mode 100644 cmd/authlibskin/build.bat create mode 100644 config/config.yaml create mode 100644 config/yaml_test.go diff --git a/cmd/authlibskin/build.bat b/cmd/authlibskin/build.bat new file mode 100644 index 0000000..82a7416 --- /dev/null +++ b/cmd/authlibskin/build.bat @@ -0,0 +1,2 @@ +SET CGO_ENABLED=0 +go build -trimpath -ldflags "-w -s" diff --git a/cmd/authlibskin/config.yaml.template b/cmd/authlibskin/config.yaml.template index fc917af..7319130 100644 --- a/cmd/authlibskin/config.yaml.template +++ b/cmd/authlibskin/config.yaml.template @@ -1,54 +1,53 @@ # 为 true 则 uuid 生成方式于离线模式相同,若从离线模式切换不会丢失数据。 # 已有用户数据的情况下勿更改此项 -OfflineUUID: true +offlineUUID: true -Port: "0.0.0.0:8080" +port: "0.0.0.0:8080" Log: Level: "debug" # json 格式输出 Json: false -Sql: - MysqlDsn: "" +sql: + mysqlDsn: "" # 输出每条执行的 sql 语句 -Debug: false +debug: false -Cache: +cache: # 默认使用内存缓存,若需要集群部署,请更换 redis - Type: "" + type: "" # 内存缓存使用大小,单位 b - Ram: 10000000 + ram: 10000000 # 位于反向代理后启用,用于记录真实 ip -RaelIP: false +raelIP: false # ip 段最大注册用户,ipv4 为 /24 ipv6 为 /48 -MaxIpUser: 10 +maxIpUser: 10 # 运行后勿修改,若为集群需设置为一致 -RsaPriKey: "" +rsaPriKey: "" # 材质文件保存路径,如果需要对象存储可以把对象储存挂载到本地目录上 -TexturePath: "skin" +texturePath: "skin" # 材质静态文件提供基础地址 # 如果静态文件位于 oss 上,比如 https://s3.amazonaws.com/example/1.png # 则填写 https://s3.amazonaws.com/example -TextureBaseUrl: "" +textureBaseUrl: "" # 用于在支持的启动器中展示本站的注册地址 # 填写类似 https://example.com -WebBaseUrl: "" +webBaseUrl: "" # 皮肤站名字,用于在多个地方展示 -ServerName: "" +serverName: "" - -Captcha: +captcha: # 验证码类型,目前只支持 cloudflare turnstile # 填写 turnstile - Type: "" - SiteKey: "" - Secret: "" + type: "" + siteKey: "" + secret: "" diff --git a/cmd/authlibskin/main.go b/cmd/authlibskin/main.go index c6f080b..6c5397f 100644 --- a/cmd/authlibskin/main.go +++ b/cmd/authlibskin/main.go @@ -30,7 +30,7 @@ func main() { if err != nil { if errors.Is(err, os.ErrNotExist) { lo.Must0(os.WriteFile("config.yaml", configTempLate, 0600)) - fmt.Println("已写入模板配置文件") + fmt.Println("未找到配置文件,已写入模板配置文件") return } panic(err) diff --git a/config/config.go b/config/config.go index 3b7ab35..ebd9b02 100644 --- a/config/config.go +++ b/config/config.go @@ -1,31 +1,31 @@ package config type Config struct { - OfflineUUID bool - Port string + OfflineUUID bool `yaml:"offlineUUID"` + Port string `yaml:"port"` Log struct { - Level string - Json bool - } + Level string `yaml:"level"` + Json bool `yaml:"json"` + } `yaml:"log"` Sql struct { - MysqlDsn string - } - Debug bool + MysqlDsn string `yaml:"mysqlDsn"` + } `yaml:"sql"` + Debug bool `yaml:"debug"` Cache struct { - Type string - Ram int - } - RaelIP bool - MaxIpUser int - RsaPriKey string - TexturePath string - TextureBaseUrl string - WebBaseUrl string - ServerName string + Type string `yaml:"type"` + Ram int `yaml:"ram"` + } `yaml:"cache"` + RaelIP bool `yaml:"raelIP"` + MaxIpUser int `yaml:"maxIpUser"` + RsaPriKey string `yaml:"rsaPriKey"` + TexturePath string `yaml:"texturePath"` + TextureBaseUrl string `yaml:"textureBaseUrl"` + WebBaseUrl string `yaml:"webBaseUrl"` + ServerName string `yaml:"serverName"` Captcha struct { - Type string - SiteKey string - Secret string - } + Type string `yaml:"type"` + SiteKey string `yaml:"siteKey"` + Secret string `yaml:"ecret"` + } `yaml:"captcha"` } diff --git a/config/config.yaml b/config/config.yaml new file mode 100644 index 0000000..55bae5c --- /dev/null +++ b/config/config.yaml @@ -0,0 +1,53 @@ +# 为 true 则 uuid 生成方式于离线模式相同,若从离线模式切换不会丢失数据。 +# 已有用户数据的情况下勿更改此项 +offlineUUID: true + +port: "127.0.0.1:8080" + +Log: + Level: "debug" + # json 格式输出 + Json: false + +sql: + mysqlDsn: "123" + +# 输出每条执行的 sql 语句 +debug: false + +cache: + # 默认使用内存缓存,若需要集群部署,请更换 redis + type: "" + # 内存缓存使用大小,单位 b + ram: 10000000 + +# 位于反向代理后启用,用于记录真实 ip +raelIP: false + +# ip 段最大注册用户,ipv4 为 /24 ipv6 为 /48 +maxIpUser: 10 + +# 运行后勿修改,若为集群需设置为一致 +rsaPriKey: "" + +# 材质文件保存路径,如果需要对象存储可以把对象储存挂载到本地目录上 +texturePath: "skin" + +# 材质静态文件提供基础地址 +# 如果静态文件位于 oss 上,比如 https://s3.amazonaws.com/example/1.png +# 则填写 https://s3.amazonaws.com/example +textureBaseUrl: "" + +# 用于在支持的启动器中展示本站的注册地址 +# 填写类似 https://example.com +webBaseUrl: "" + +# 皮肤站名字,用于在多个地方展示 +serverName: "" + +captcha: + # 验证码类型,目前只支持 cloudflare turnstile + # 填写 turnstile + type: "" + siteKey: "" + secret: "" diff --git a/config/yaml.go b/config/yaml.go index b471736..fb2de93 100644 --- a/config/yaml.go +++ b/config/yaml.go @@ -12,5 +12,6 @@ func YamlDeCode(b []byte) (Config, error) { if err != nil { return c, fmt.Errorf("YamlDeCode: %w", err) } + fmt.Println(c) return c, nil } diff --git a/config/yaml_test.go b/config/yaml_test.go new file mode 100644 index 0000000..24d2bc2 --- /dev/null +++ b/config/yaml_test.go @@ -0,0 +1,20 @@ +package config + +import ( + "os" + "testing" +) + +func TestYamlDeCode(t *testing.T) { + b, err := os.ReadFile("config.yaml") + if err != nil { + t.Fatal(err) + } + c, err := YamlDeCode(b) + if err != nil { + t.Fatal(err) + } + if c.Sql.MysqlDsn != "123" { + t.FailNow() + } +}