Skip to content

Commit e1a7d74

Browse files
committed
update hade framework
1 parent 22f77db commit e1a7d74

File tree

388 files changed

+34358
-12055
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

388 files changed

+34358
-12055
lines changed

LICENSE

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
MIT License
1+
The MIT License (MIT)
22

3-
Copyright (c) 2017-present PanJiaChen
3+
Copyright (c) 2021 jianfengye
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal
@@ -9,13 +9,13 @@ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
99
copies of the Software, and to permit persons to whom the Software is
1010
furnished to do so, subject to the following conditions:
1111

12-
The above copyright notice and this permission notice shall be included in all
13-
copies or substantial portions of the Software.
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
1414

1515
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1616
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1717
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1818
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1919
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21-
SOFTWARE.
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

README.md

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,29 @@
1-
hade框架文件
1+
# 官方网站
22

3+
http://hade.funaio.cn/
34

4-
目前还处于alpha版本,请使用go get -u hade 实时更新
5+
# 框架特色:
6+
7+
## 基于协议
8+
9+
服务与服务间的协议是基于协议进行交互的。
10+
11+
## 前后端协同
12+
13+
前后端协同开发
14+
15+
## 命令行
16+
17+
有充分的命令行工具
18+
19+
## 集成定时服务
20+
21+
如果你需要启动定时服务,提供命令进行定时服务的启动
22+
23+
## 文档丰富
24+
25+
提供丰富的文档说明,提供丰富的文档说明
26+
27+
## 开发模式
28+
29+
在开发模式下进行前后端开发,极大提高了开发效率和开发体验

app/console/command/demo.go

Lines changed: 0 additions & 18 deletions
This file was deleted.

app/console/command/demo/foo.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package demo
2+
3+
import (
4+
"fmt"
5+
"github.com/gohade/hade/framework/cobra"
6+
"github.com/gohade/hade/framework/contract"
7+
"log"
8+
)
9+
10+
// InitFoo 初始化Foo命令
11+
func InitFoo() *cobra.Command {
12+
FooCommand.AddCommand(Foo1Command)
13+
return FooCommand
14+
}
15+
16+
// FooCommand 代表Foo命令
17+
var FooCommand = &cobra.Command{
18+
Use: "foo",
19+
Short: "foo的简要说明",
20+
Long: "foo的长说明",
21+
Aliases: []string{"fo", "f"},
22+
Example: "foo命令的例子",
23+
RunE: func(c *cobra.Command, args []string) error {
24+
configService := c.GetContainer().MustMake(contract.ConfigKey).(contract.Config)
25+
envService := c.GetContainer().MustMake(contract.EnvKey).(contract.Env)
26+
fmt.Println("APP_ENV: ", envService.Get("APP_ENV"))
27+
fmt.Println("FOO_ENV: ", envService.Get("FOO_ENV"))
28+
29+
fmt.Println("config url:", configService.GetString("app.url"))
30+
return nil
31+
},
32+
}
33+
34+
// Foo1Command 代表Foo命令的子命令Foo1
35+
var Foo1Command = &cobra.Command{
36+
Use: "foo1",
37+
Short: "foo1的简要说明",
38+
Long: "foo1的长说明",
39+
Aliases: []string{"fo1", "f1"},
40+
Example: "foo1命令的例子",
41+
RunE: func(c *cobra.Command, args []string) error {
42+
container := c.GetContainer()
43+
log.Println(container)
44+
return nil
45+
},
46+
}

app/console/command/demo2.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package command
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/gohade/hade/framework/cobra"
7+
)
8+
9+
var Demo2Command = &cobra.Command{
10+
Use: "demo2",
11+
Short: "demo2",
12+
RunE: func(c *cobra.Command, args []string) error {
13+
container := c.GetContainer()
14+
fmt.Println(container)
15+
return nil
16+
},
17+
}
18+

app/console/kernel.go

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,49 @@
11
package console
22

33
import (
4+
"github.com/gohade/hade/app/console/command/demo"
45
"github.com/gohade/hade/framework"
56
"github.com/gohade/hade/framework/cobra"
6-
hadeCommand "github.com/gohade/hade/framework/command"
7-
commandUtil "github.com/gohade/hade/framework/command/util"
7+
"github.com/gohade/hade/framework/command"
88
)
99

10-
// RunCommand is command
10+
// RunCommand 初始化根Command并运行
1111
func RunCommand(container framework.Container) error {
12+
// 根Command
1213
var rootCmd = &cobra.Command{
13-
Use: "hade",
14-
Short: "main",
15-
Long: "hade commands",
14+
// 定义根命令的关键字
15+
Use: "hade",
16+
// 简短介绍
17+
Short: "hade 命令",
18+
// 根命令的详细介绍
19+
Long: "hade 框架提供的命令行工具,使用这个命令行工具能很方便执行框架自带命令,也能很方便编写业务命令",
20+
// 根命令的执行函数
21+
RunE: func(cmd *cobra.Command, args []string) error {
22+
cmd.InitDefaultHelpFlag()
23+
return cmd.Help()
24+
},
25+
// 不需要出现cobra默认的completion子命令
26+
CompletionOptions: cobra.CompletionOptions{DisableDefaultCmd: true},
1627
}
1728

18-
ctx := commandUtil.RegiestContainer(container, rootCmd)
29+
// 为根Command设置服务容器
30+
rootCmd.SetContainer(container)
31+
// 绑定框架的命令
32+
command.AddKernelCommands(rootCmd)
33+
// 绑定业务的命令
34+
AddAppCommand(rootCmd)
1935

20-
hadeCommand.AddKernelCommands(rootCmd)
36+
// 执行RootCommand
37+
return rootCmd.Execute()
38+
}
39+
40+
// 绑定业务的命令
41+
func AddAppCommand(rootCmd *cobra.Command) {
42+
rootCmd.AddCommand(demo.FooCommand)
2143

22-
// rootCmd.AddCronCommand("* * * * *", command.DemoCommand)
44+
// 每秒调用一次Foo命令
45+
//rootCmd.AddCronCommand("* * * * * *", demo.FooCommand)
2346

24-
return rootCmd.ExecuteContext(ctx)
47+
// 启动一个分布式任务调度,调度的服务名称为init_func_for_test,每个节点每5s调用一次Foo命令,抢占到了调度任务的节点将抢占锁持续挂载2s才释放
48+
//rootCmd.AddDistributedCronCommand("foo_func_for_test", "*/5 * * * * *", demo.FooCommand, 2*time.Second)
2549
}

app/http/kernel.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,16 @@ import (
44
"github.com/gohade/hade/framework/gin"
55
)
66

7-
// NewHttpEngine is command
7+
// NewHttpEngine 创建了一个绑定了路由的Web引擎
88
func NewHttpEngine() (*gin.Engine, error) {
9+
// 设置为Release,为的是默认在启动中不输出调试信息
910
gin.SetMode(gin.ReleaseMode)
10-
r := gin.Default()
11+
// 默认启动一个Web引擎
12+
r := gin.New()
13+
r.Use(gin.Recovery())
1114

15+
// 业务绑定路由操作
1216
Routes(r)
17+
// 返回绑定路由后的Web引擎
1318
return r, nil
1419
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: Run Tests
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
branches:
9+
- master
10+
11+
jobs:
12+
lint:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Setup go
16+
uses: actions/setup-go@v2
17+
with:
18+
go-version: '^1.16'
19+
- name: Checkout repository
20+
uses: actions/checkout@v2
21+
- name: Setup golangci-lint
22+
uses: golangci/golangci-lint-action@v2
23+
with:
24+
version: v1.42.1
25+
args: --verbose
26+
test:
27+
strategy:
28+
matrix:
29+
os: [ubuntu-latest, macos-latest]
30+
go: [1.13, 1.14, 1.15, 1.16, 1.17]
31+
include:
32+
- os: ubuntu-latest
33+
go-build: ~/.cache/go-build
34+
- os: macos-latest
35+
go-build: ~/Library/Caches/go-build
36+
name: ${{ matrix.os }} @ Go ${{ matrix.go }}
37+
runs-on: ${{ matrix.os }}
38+
env:
39+
GO111MODULE: on
40+
GOPROXY: https://proxy.golang.org
41+
steps:
42+
- name: Set up Go ${{ matrix.go }}
43+
uses: actions/setup-go@v2
44+
with:
45+
go-version: ${{ matrix.go }}
46+
47+
- name: Checkout Code
48+
uses: actions/checkout@v2
49+
with:
50+
ref: ${{ github.ref }}
51+
52+
- uses: actions/cache@v2
53+
with:
54+
path: |
55+
${{ matrix.go-build }}
56+
~/go/pkg/mod
57+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
58+
restore-keys: |
59+
${{ runner.os }}-go-
60+
- name: Run Tests
61+
run: |
62+
go test -v -covermode=atomic -coverprofile=coverage.out
63+
64+
- name: Upload coverage to Codecov
65+
uses: codecov/codecov-action@v2
66+
with:
67+
flags: ${{ matrix.os }},go-${{ matrix.go }}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
*.o
2+
*.a
3+
*.so
4+
5+
_obj
6+
_test
7+
8+
*.[568vq]
9+
[568vq].out
10+
11+
*.cgo1.go
12+
*.cgo2.c
13+
_cgo_defun.c
14+
_cgo_gotypes.go
15+
_cgo_export.*
16+
17+
_testmain.go
18+
19+
*.exe
20+
*.test
21+
*.prof
22+
23+
coverage.out
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2017 Swaggo
3+
Copyright (c) 2016 Gin-Gonic
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

0 commit comments

Comments
 (0)