-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
152 changed files
with
2,989 additions
and
4,439 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# SPDX-FileCopyrightText: 2024 caixw | ||
# | ||
# SPDX-License-Identifier: MIT | ||
|
||
.PHONY: api gen watch build install | ||
|
||
ROOT = . | ||
DOCS = $(ROOT)/docs | ||
API = $(DOCS)/api | ||
TARGET = $(ROOT)/cmd/server | ||
BIN = $(TARGET)/server | ||
|
||
dist = ./dist | ||
|
||
# 生成 API 文件 | ||
api: | ||
web restdoc -o=$(API)/restdoc.json | ||
|
||
gen: | ||
go generate ./... | ||
|
||
build: | ||
web build -o=$(BIN) -v $(TARGET) | ||
|
||
install: | ||
cd $(TARGET) && ./server -a=install | ||
|
||
watch: | ||
web watch -app=-a=serve $(TARGET) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
server | ||
server.db | ||
logs/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// SPDX-FileCopyrightText: 2022-2024 caixw | ||
// | ||
// SPDX-License-Identifier: MIT | ||
|
||
package main | ||
|
||
import ( | ||
"github.com/issue9/cmfx/cmfx" | ||
"github.com/issue9/cmfx/cmfx/inital/cmd" | ||
|
||
_ "github.com/mattn/go-sqlite3" | ||
) | ||
|
||
func main() { | ||
if err := cmd.Exec("cmfx", cmfx.Version); err != nil { | ||
panic(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// SPDX-FileCopyrightText: 2022-2024 caixw | ||
// | ||
// 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 | ||
|
||
// Package cmfx 基于 https://github.com/issue9/web 框架的一些通用模块 | ||
package cmfx | ||
|
||
// # restdoc cmfx 文档 | ||
// | ||
// @media application/json application/xml | ||
// @version [Version] | ||
// @tag admin 管理员端 | ||
// @tag rbac RBAC | ||
// @resp 4XX * github.com/issue9/web.Problem | ||
// @resp 5XX * github.com/issue9/web.Problem desc | ||
|
||
import ( | ||
"github.com/issue9/web" | ||
"github.com/issue9/web/locales" | ||
) | ||
|
||
// Version 表示当前框架的版本 | ||
const Version = "0.7.0" | ||
|
||
// 定义可用的错误代码 | ||
const ( | ||
BadRequest = web.ProblemBadRequest | ||
BadRequestInvalidPath = "40001" | ||
BadRequestInvalidQuery = "40002" | ||
BadRequestInvalidHeader = "40003" | ||
BadRequestInvalidBody = "40004" | ||
) | ||
|
||
// 401 | ||
const ( | ||
Unauthorized = web.ProblemUnauthorized | ||
UnauthorizedInvalidState = "40101" | ||
UnauthorizedInvalidToken = "40102" | ||
UnauthorizedSecurityToken = "40103" // 需要强验证 | ||
UnauthorizedInvalidAccount = "40104" // 无效的账号或密码 | ||
UnauthorizedNeedChangePassword = "40105" | ||
|
||
// 可注册的状态,比如 OAuth2 验证,如果未注册,返回一个 ID 可用以注册。 | ||
UnauthorizedRegistrable = "40106" | ||
) | ||
|
||
// 403 | ||
const ( | ||
Forbidden = web.ProblemForbidden | ||
ForbiddenStateNotAllow = "40301" | ||
ForbiddenCaNotDeleteYourself = "40302" | ||
) | ||
|
||
func ErrNotFound() error { return locales.ErrNotFound() } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// SPDX-FileCopyrightText: 2022-2024 caixw | ||
// | ||
// SPDX-License-Identifier: MIT | ||
|
||
// Package filters 通用过滤器 | ||
package filters | ||
|
||
import ( | ||
"github.com/issue9/web/filter" | ||
v "github.com/issue9/webfilter/validator" | ||
|
||
"github.com/issue9/cmfx/locales" | ||
) | ||
|
||
func NilOr[T any](validator func(T) bool) filter.Builder[T] { | ||
return filter.NewBuilder(v.V(v.Or(validator, v.Nil), locales.InvalidValue)) | ||
} | ||
|
||
func Nil[T any]() filter.Builder[T] { | ||
return filter.NewBuilder(v.V[T](v.Nil, locales.MustBeEmpty)) | ||
} | ||
|
||
// NotZero 非零值 | ||
func NotZero[T any]() filter.Builder[T] { | ||
return filter.NewBuilder(v.V(v.Not(v.Zero[T]), locales.Required)) | ||
} | ||
|
||
func Zero[T any]() filter.Builder[T] { | ||
return filter.NewBuilder(v.V(v.Zero[T], locales.Required)) | ||
} | ||
|
||
func Equal[T comparable](val T) filter.Builder[T] { | ||
return filter.NewBuilder(v.V(v.Equal(val), locales.InvalidValue)) | ||
} | ||
|
||
func NotEqual[T comparable](val T) filter.Builder[T] { | ||
return filter.NewBuilder(v.V(v.Not(v.Equal(val)), locales.InvalidValue)) | ||
} |
Oops, something went wrong.