Skip to content

Commit

Permalink
chore: 调整目录和翻译内容
Browse files Browse the repository at this point in the history
  • Loading branch information
caixw committed Jun 2, 2024
1 parent d7b608e commit 9919511
Show file tree
Hide file tree
Showing 11 changed files with 210 additions and 146 deletions.
20 changes: 11 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,29 @@

ROOT = .
DOCS = $(ROOT)/docs
API = $(DOCS)/api
TARGET = $(ROOT)/cmd/server
BIN = $(TARGET)/server
DEMO = $(ROOT)/demo
CMFX = $(ROOT)/cmfx
ADMIN = $(ROOT)/admin

dist = ./dist
DOC_API = $(DOCS)/api
DEMO_SERVER = $(DEMO)/server
SERVER_BIN = server

# 生成 API 文件
api:
web restdoc -t=admin,common -o=$(API)/admin.yaml $(ROOT)/cmfx
web restdoc -t=admin,common -o=$(DOC_API)/admin.yaml $(CMFX)

# 生成 go 的依赖内容
gen:
go generate ./...
go generate $(ROOT)/...

# 编译测试项目
build:
web build -o=$(BIN) -v $(TARGET)
web build -o=$(DEMO_SERVER)/$(SERVER_BIN) -v $(DEMO_SERVER)

# 安装基本数据,依赖上一步的 build 生成的测试项目
install:
cd $(TARGET) && ./server -a=install
cd $(DEMO_SERVER) && ./server -a=install

watch:
web watch -app=-a=serve $(TARGET)
web watch -app=-a=serve $(DEMO_SERVER)
10 changes: 3 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,9 @@

## 目录结构

- cmd 命令行
- cmfx 后端主目录
- cmfx/modules 通用模块,模块只能是单例;
- admin 前端管理后台的主目录
- cmfx 后端源码的主目录
- demo 一些演示用例
- locales 本地化内容;

- web 前端
- dist 前端编译后的内容

- docs 文档
- docs/api API 文档
4 changes: 2 additions & 2 deletions cmfx/cmfx.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
//
// SPDX-License-Identifier: MIT

//go:generate web locale -l=und -m -f=yaml ./
//go:generate web update-locale -src=./locales/und.yaml -dest=./locales/zh-CN.yaml
//go:generate web locale -l=und -m -f=yaml -o=../locales ./
//go:generate web update-locale -src=../locales/und.yaml -dest=../locales/zh-CN.yaml

// Package cmfx 基于 https://github.com/issue9/web 框架的一些通用模块
package cmfx
Expand Down
30 changes: 15 additions & 15 deletions cmfx/types/enums_methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/issue9/web/locales"
)

//---------------------Sex------------------------
//--------------------- Sex ------------------------

var _SexToString = map[Sex]string{
SexFemale: "female",
Expand All @@ -25,11 +25,11 @@ var _SexFromString = map[string]Sex{
}

// String fmt.Stringer
func (S Sex) String() string {
if v, found := _SexToString[S]; found {
func (s Sex) String() string {
if v, found := _SexToString[s]; found {
return v
}
return fmt.Sprintf("Sex(%d)", S)
return fmt.Sprintf("Sex(%d)", s)
}

func ParseSex(v string) (Sex, error) {
Expand All @@ -40,29 +40,29 @@ func ParseSex(v string) (Sex, error) {
}

// MarshalText encoding.TextMarshaler
func (S Sex) MarshalText() ([]byte, error) {
if v, found := _SexToString[S]; found {
func (s Sex) MarshalText() ([]byte, error) {
if v, found := _SexToString[s]; found {
return []byte(v), nil
}
return nil, locales.ErrInvalidValue()
}

// UnmarshalText encoding.TextUnmarshaler
func (S *Sex) UnmarshalText(p []byte) error {
func (s *Sex) UnmarshalText(p []byte) error {
tmp, err := ParseSex(string(p))
if err == nil {
*S = tmp
*s = tmp
}
return err
}

func (S Sex) IsValid() bool {
_, found := _SexToString[S]
func (s Sex) IsValid() bool {
_, found := _SexToString[s]
return found
}

// Scan sql.Scanner
func (S *Sex) Scan(src any) error {
func (s *Sex) Scan(src any) error {
if src == nil {
return locales.ErrInvalidValue()
}
Expand All @@ -84,13 +84,13 @@ func (S *Sex) Scan(src any) error {
return err
}

*S = v
*s = v
return nil
}

// Value driver.Valuer
func (S Sex) Value() (driver.Value, error) {
v, err := S.MarshalText()
func (s Sex) Value() (driver.Value, error) {
v, err := s.MarshalText()
if err != nil {
return nil, err
}
Expand All @@ -109,4 +109,4 @@ var (
SexSliceFilter = filter.NewBuilder(SexSliceRule)
)

//---------------------end Sex--------------------
//--------------------- end Sex --------------------
2 changes: 1 addition & 1 deletion cmfx/user/passport/oauth/oauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (o *OAuth[T]) AuthURL() string { return o.config.AuthCodeURL(o.state) }
// state 为 oauth2 服务从 [OAuth.AuthURL] 返回的值;
func (o *OAuth[T]) Valid(state, code string, _ time.Time) (int64, string, error) {
if state != o.state {
return 0, "", web.NewLocaleError("different state %s %s", state, o.state)
return 0, "", web.NewLocaleError("different oauth state value %s %s", state, o.state)
}

token, err := o.config.Exchange(context.Background(), code)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
52 changes: 38 additions & 14 deletions docs/api/admin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ components:
language:
type: string
title: 界面语言
description: |
界面语言
不会直接影响服务的处理,客户端自行决定是否采用。服务采用客户端的 Accept-Language 决定使用哪种语言。
name:
type: string
title: 真实名称
Expand Down Expand Up @@ -45,6 +49,10 @@ components:
timezone:
type: string
title: 时区
description: |
时区
不会直接影响服务的处理,客户端自行决定是否采用。
github.com.issue9.cmfx.cmfx.modules.admin.info:
type: object
title: 管理员的基本信息
Expand All @@ -62,6 +70,10 @@ components:
language:
type: string
title: 界面语言
description: |
界面语言
不会直接影响服务的处理,客户端自行决定是否采用。服务采用客户端的 Accept-Language 决定使用哪种语言。
name:
type: string
title: 真实名称
Expand All @@ -77,6 +89,10 @@ components:
timezone:
type: string
title: 时区
description: |
时区
不会直接影响服务的处理,客户端自行决定是否采用。
github.com.issue9.cmfx.cmfx.modules.admin.reqInfoWithAccount:
type: object
properties:
Expand All @@ -91,6 +107,10 @@ components:
language:
type: string
title: 界面语言
description: |
界面语言
不会直接影响服务的处理,客户端自行决定是否采用。服务采用客户端的 Accept-Language 决定使用哪种语言。
name:
type: string
title: 真实名称
Expand Down Expand Up @@ -122,6 +142,10 @@ components:
timezone:
type: string
title: 时区
description: |
时区
不会直接影响服务的处理,客户端自行决定是否采用。
username:
type: string
github.com.issue9.cmfx.cmfx.modules.admin.reqPassword:
Expand Down Expand Up @@ -745,6 +769,11 @@ paths:
- admin
summary: 获取所有的管理员账号
parameters:
- name: page
in: query
schema:
type: integer
title: 请求的页码,从 0 开始。
- name: role
in: query
schema:
Expand All @@ -757,12 +786,21 @@ paths:
type: array
items:
$ref: '#/components/schemas/github.com.issue9.cmfx.cmfx.types.Sex'
- name: size
in: query
schema:
type: integer
title: 每页的数量
- name: state
in: query
schema:
type: array
items:
$ref: '#/components/schemas/github.com.issue9.cmfx.cmfx.user.State'
- name: text
in: query
schema:
type: string
responses:
4XX:
$ref: '#/components/responses/4XX'
Expand Down Expand Up @@ -1306,20 +1344,6 @@ paths:
type: string
title: 创建日志的起始时间
format: date-time
- name: page
in: query
schema:
type: integer
title: 请求的页码,从 0 开始。
- name: size
in: query
schema:
type: integer
title: 每页的数量
- name: text
in: query
schema:
type: string
responses:
4XX:
$ref: '#/components/responses/4XX'
Expand Down
Loading

0 comments on commit 9919511

Please sign in to comment.