完成了 程序阻止

This commit is contained in:
yumaojun03 2024-12-08 17:00:22 +08:00
parent e7ee8b3f20
commit dff4f15b04
11 changed files with 118 additions and 13 deletions

View File

@ -1,3 +1,5 @@
{
"go.testEnvFile": "${workspaceFolder}/etc/test.env",
"go.testEnvVars": {
"WORKSPACE_DIR": "${workspaceFolder}"
}
}

View File

@ -183,7 +183,7 @@ func (u *UserServiceImpl) Registry(ctx context.Context, in *user.RegistryRequest
}
```
### 接口层
### API接口层
Gin
```go
@ -242,4 +242,16 @@ func (h *TokenApiHandler) RevolkToken(ctx *gin.Context) {
}
response.Success(ctx, ins)
}
```
```
### 组装程序
怎么做开发显得专业
### 中间件鉴权
### ioc优化

View File

@ -4,12 +4,27 @@ import (
"github.com/gin-gonic/gin"
"github.com/infraboard/mcube/v2/http/gin/response"
"gitlab.com/go-course-project/go17/vblog/apps/blog"
"gitlab.com/go-course-project/go17/vblog/apps/blog/impl"
)
func NewBlogApiHandler() *BlogApiHandler {
return &BlogApiHandler{
blog: impl.BlogService,
}
}
type BlogApiHandler struct {
blog blog.Service
}
// 提供注册功能, 提供一个Group
// book := server.Group("/api/tokens")
func (h *BlogApiHandler) Registry(r *gin.Engine) {
router := r.Group("/api/blogs")
router.POST("", h.CreateBlog)
router.GET("", h.QueryBlog)
}
// BODY
func (h *BlogApiHandler) CreateBlog(ctx *gin.Context) {
in := &blog.CreateBlogRequest{}

View File

@ -5,7 +5,7 @@ import (
"github.com/infraboard/mcube/v2/ioc/config/datasource"
"gitlab.com/go-course-project/go17/vblog/apps/blog"
"gitlab.com/go-course-project/go17/vblog/test"
"gitlab.com/go-course-project/go17/vblog/config"
)
func TestMigrate(t *testing.T) {
@ -16,5 +16,5 @@ func TestMigrate(t *testing.T) {
}
func init() {
test.DevelopmentSetup()
config.LoadConfig()
}

View File

@ -5,7 +5,7 @@ import (
"github.com/infraboard/mcube/v2/ioc/config/datasource"
"gitlab.com/go-course-project/go17/vblog/apps/token"
"gitlab.com/go-course-project/go17/vblog/test"
"gitlab.com/go-course-project/go17/vblog/config"
)
func TestMigrate(t *testing.T) {
@ -16,5 +16,5 @@ func TestMigrate(t *testing.T) {
}
func init() {
test.DevelopmentSetup()
config.LoadConfig()
}

View File

@ -5,7 +5,7 @@ import (
"github.com/infraboard/mcube/v2/ioc/config/datasource"
"gitlab.com/go-course-project/go17/vblog/apps/user"
"gitlab.com/go-course-project/go17/vblog/test"
"gitlab.com/go-course-project/go17/vblog/config"
)
func TestMigrate(t *testing.T) {
@ -16,5 +16,5 @@ func TestMigrate(t *testing.T) {
}
func init() {
test.DevelopmentSetup()
config.LoadConfig()
}

View File

@ -1,4 +1,4 @@
package test
package config
import (
"os"
@ -6,12 +6,18 @@ import (
"github.com/infraboard/mcube/v2/ioc"
)
func DevelopmentSetup() {
func LoadConfig() {
// 配置单元单元测试的配置, application.toml
req := ioc.NewLoadConfigRequest()
req.ConfigFile.Enabled = true
// 必须配置绝对逻辑, {Workspace}
req.ConfigFile.Path = os.Getenv("WORKSPACE_DIR") + "/etc/application.toml"
workspaceDir := os.Getenv("WORKSPACE_DIR")
if workspaceDir == "" {
req.ConfigFile.Path = "etc/application.toml"
} else {
req.ConfigFile.Path = workspaceDir + "/etc/application.toml"
}
err := ioc.ConfigIocObject(req)
if err != nil {
panic(err)

View File

@ -0,0 +1,43 @@
<mxfile host="65bd71144e">
<diagram id="7RU3wE6LOVUHdx5pdp2v" name="第 1 页">
<mxGraphModel dx="937" dy="470" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="827" pageHeight="1169" math="0" shadow="0">
<root>
<mxCell id="0"/>
<mxCell id="1" parent="0"/>
<mxCell id="2" value="" style="shape=flexArrow;endArrow=classic;html=1;endWidth=46;endSize=7.36;" edge="1" parent="1">
<mxGeometry width="50" height="50" relative="1" as="geometry">
<mxPoint x="170" y="80" as="sourcePoint"/>
<mxPoint x="170" y="310" as="targetPoint"/>
</mxGeometry>
</mxCell>
<mxCell id="3" value="面向过程" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" vertex="1" parent="1">
<mxGeometry x="90" y="20" width="60" height="30" as="geometry"/>
</mxCell>
<mxCell id="5" value="入口" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" vertex="1" parent="1">
<mxGeometry x="80" y="70" width="60" height="30" as="geometry"/>
</mxCell>
<mxCell id="6" value="入口" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" vertex="1" parent="1">
<mxGeometry x="320" y="80" width="60" height="30" as="geometry"/>
</mxCell>
<mxCell id="7" value="" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="200" y="80" width="90" height="210" as="geometry"/>
</mxCell>
<mxCell id="8" value="" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="430" y="80" width="90" height="210" as="geometry"/>
</mxCell>
<mxCell id="9" value="" style="shape=flexArrow;endArrow=classic;html=1;endWidth=46;endSize=7.36;" edge="1" parent="1">
<mxGeometry width="50" height="50" relative="1" as="geometry">
<mxPoint x="390" y="300" as="sourcePoint"/>
<mxPoint x="390" y="80" as="targetPoint"/>
</mxGeometry>
</mxCell>
<mxCell id="10" value="面向对象" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" vertex="1" parent="1">
<mxGeometry x="354" y="20" width="60" height="30" as="geometry"/>
</mxCell>
<mxCell id="11" value="业务设计" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="430" y="170" width="90" height="120" as="geometry"/>
</mxCell>
</root>
</mxGraphModel>
</diagram>
</mxfile>

View File

@ -2,7 +2,7 @@
# HTTP服务Host
host = "127.0.0.1"
# HTTP服务端口
port = 8010
port = 8080
[datasource]
provider = "mysql"

27
vblog/main.go Normal file
View File

@ -0,0 +1,27 @@
package main
import (
"log"
"github.com/gin-gonic/gin"
"github.com/infraboard/mcube/v2/ioc/config/http"
blogApi "gitlab.com/go-course-project/go17/vblog/apps/blog/api"
tokenApi "gitlab.com/go-course-project/go17/vblog/apps/token/api"
"gitlab.com/go-course-project/go17/vblog/config"
)
func main() {
config.LoadConfig()
// gin Engine, 它包装了http server
server := gin.Default()
// 注册业务模块的路有
tokenApi.NewTokenApiHandler().Registry(server)
blogApi.NewBlogApiHandler().Registry(server)
// 服务器启动
if err := server.Run(http.Get().Addr()); err != nil {
log.Println(err)
}
}