[octopus-go] 新增部分代码
This commit is contained in:
@@ -16,10 +16,14 @@ func (s *ServerRouter) InitServerRouter(Router *gin.RouterGroup) {
|
|||||||
|
|
||||||
serverAPIService := service.ServerAPIService
|
serverAPIService := service.ServerAPIService
|
||||||
{
|
{
|
||||||
serverRouter.GET("/info/all", serverAPIService.QueryAPI)
|
|
||||||
|
|
||||||
serverRouter.GET("/info/fake", serverAPIService.FakeAPI)
|
serverRouter.GET("/info/fake", serverAPIService.FakeAPI)
|
||||||
|
|
||||||
|
// 服务器 CRUD接口及方法
|
||||||
|
serverRouter.GET("/info/all", serverAPIService.QueryAPI)
|
||||||
serverRouter.POST("/create/one", serverAPIService.CreateAPI)
|
serverRouter.POST("/create/one", serverAPIService.CreateAPI)
|
||||||
|
serverRouter.POST("/update/one", serverAPIService.UpdateAPI)
|
||||||
|
serverRouter.POST("/delete/one", serverAPIService.DeleteAPI)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ type ServerAPI struct {
|
|||||||
|
|
||||||
var ServerAPIService = new(ServerAPI)
|
var ServerAPIService = new(ServerAPI)
|
||||||
|
|
||||||
|
var db = entity.CONGIG.DB
|
||||||
|
|
||||||
func (s *ServerAPI) QueryAPI(c *gin.Context) {
|
func (s *ServerAPI) QueryAPI(c *gin.Context) {
|
||||||
|
|
||||||
fmt.Println("ServerAPI -> QueryAPI")
|
fmt.Println("ServerAPI -> QueryAPI")
|
||||||
@@ -28,8 +30,6 @@ func (s *ServerAPI) CreateAPI(c *gin.Context) {
|
|||||||
|
|
||||||
fmt.Sprintf("server info is => %s", serverInfo)
|
fmt.Sprintf("server info is => %s", serverInfo)
|
||||||
|
|
||||||
db := entity.CONGIG.DB
|
|
||||||
|
|
||||||
create := db.Create(&serverInfo)
|
create := db.Create(&serverInfo)
|
||||||
//user.ID // 返回插入数据的主键
|
//user.ID // 返回插入数据的主键
|
||||||
//result.Error // 返回 error
|
//result.Error // 返回 error
|
||||||
@@ -45,3 +45,47 @@ func (s *ServerAPI) FakeAPI(c *gin.Context) {
|
|||||||
http.StatusOK,
|
http.StatusOK,
|
||||||
new(entity.ServerInfo))
|
new(entity.ServerInfo))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UpdateAPI 根据前端传递的参数id进行更新
|
||||||
|
func (s *ServerAPI) UpdateAPI(c *gin.Context) {
|
||||||
|
|
||||||
|
var jsonServerInfo entity.ServerInfo
|
||||||
|
|
||||||
|
err := c.ShouldBindJSON(&jsonServerInfo)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
id := jsonServerInfo.ID
|
||||||
|
|
||||||
|
// 查询要更新的记录
|
||||||
|
var dbProduct entity.ServerInfo
|
||||||
|
if err := db.First(&dbProduct, id).Error; err != nil {
|
||||||
|
c.JSON(http.StatusNotFound, gin.H{"error": "Record not found"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 绑定模型并更新属性
|
||||||
|
db.Model(&dbProduct).Updates(jsonServerInfo)
|
||||||
|
|
||||||
|
// 保存更改并提交事务
|
||||||
|
if err := db.Save(&dbProduct).Error; err != nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to update record"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
c.JSON(http.StatusOK, dbProduct)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteAPI 跟俊前端传递的id进行删除
|
||||||
|
func (s *ServerAPI) DeleteAPI(c *gin.Context) {
|
||||||
|
|
||||||
|
// 获取前端传递的值
|
||||||
|
id := c.Param("id")
|
||||||
|
|
||||||
|
// 根据ID删除 是否是软删除
|
||||||
|
db.Delete(&entity.ServerInfo{}, id)
|
||||||
|
|
||||||
|
// 软删除
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
37
agent-go/test/channelTest.go
Normal file
37
agent-go/test/channelTest.go
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
func sum(start, end uint64, result chan uint64) {
|
||||||
|
var sum uint64 = 0
|
||||||
|
for i := start; i <= end; i++ {
|
||||||
|
sum += i
|
||||||
|
}
|
||||||
|
result <- sum
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
const n uint64 = 5000000000
|
||||||
|
var numCPU int = 4
|
||||||
|
|
||||||
|
result := make(chan uint64, numCPU)
|
||||||
|
|
||||||
|
var chunkSize uint64 = n / uint64(numCPU)
|
||||||
|
|
||||||
|
var start uint64 = 1
|
||||||
|
var end uint64 = chunkSize
|
||||||
|
|
||||||
|
for i := 0; i < numCPU; i++ {
|
||||||
|
go sum(start, end, result)
|
||||||
|
start = end + 1
|
||||||
|
end += chunkSize
|
||||||
|
}
|
||||||
|
|
||||||
|
var total uint64 = 0
|
||||||
|
for i := 0; i < numCPU; i++ {
|
||||||
|
partialSum := <-result
|
||||||
|
total += partialSum
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println(total)
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -3,7 +3,6 @@
|
|||||||
Seoul-amd64-04-f301ac,
|
Seoul-amd64-04-f301ac,
|
||||||
Tokyo-amd64-03-99907c,
|
Tokyo-amd64-03-99907c,
|
||||||
Shanghai-amd64-01-259df5->Seoul-amd64-04-f301ac,
|
Shanghai-amd64-01-259df5->Seoul-amd64-04-f301ac,
|
||||||
Shanghai-amd64-01-259df5->Seoul-amd64-04-f301ac->Tokyo-amd64-03-99907c,
|
|
||||||
Shanghai-amd64-01-259df5->Seoul-amd64-04-f301ac->Tokyo-amd64-02-439bec,
|
Shanghai-amd64-01-259df5->Seoul-amd64-04-f301ac->Tokyo-amd64-02-439bec,
|
||||||
Shanghai-amd64-01-259df5->Seoul-amd64-04-f301ac->Phoenix-amd64-02-2a45bb,
|
Shanghai-amd64-01-259df5->Seoul-amd64-04-f301ac->Phoenix-amd64-02-2a45bb,
|
||||||
Shanghai-amd64-01-259df5->Seoul-amd64-04-f301ac->London-amd64-01-0b219f
|
Shanghai-amd64-01-259df5->Seoul-amd64-04-f301ac->London-amd64-01-0b219f
|
||||||
|
|||||||
Reference in New Issue
Block a user