[octopus-go] 初步完成gin gorm框架集成
This commit is contained in:
47
agent-go/service/ServerAPI.go
Normal file
47
agent-go/service/ServerAPI.go
Normal file
@@ -0,0 +1,47 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"agent-go/entity"
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type ServerAPI struct {
|
||||
}
|
||||
|
||||
var ServerAPIService = new(ServerAPI)
|
||||
|
||||
func (s *ServerAPI) QueryAPI(c *gin.Context) {
|
||||
|
||||
fmt.Println("ServerAPI -> QueryAPI")
|
||||
}
|
||||
|
||||
func (s *ServerAPI) CreateAPI(c *gin.Context) {
|
||||
|
||||
var serverInfo entity.ServerInfo
|
||||
// get the body
|
||||
err := c.ShouldBindJSON(&serverInfo)
|
||||
if err != nil {
|
||||
fmt.Println("server info error! pls check !")
|
||||
}
|
||||
|
||||
fmt.Sprintf("server info is => %s", serverInfo)
|
||||
|
||||
db := entity.CONGIG.DB
|
||||
|
||||
create := db.Create(&serverInfo)
|
||||
//user.ID // 返回插入数据的主键
|
||||
//result.Error // 返回 error
|
||||
//result.RowsAffected // 返回插入记录的条数
|
||||
|
||||
fmt.Sprintf(
|
||||
"inter id is %s , resul error is %s, RowsAffected is %d ", serverInfo.ID, create.Error, create.RowsAffected)
|
||||
}
|
||||
|
||||
func (s *ServerAPI) FakeAPI(c *gin.Context) {
|
||||
|
||||
c.JSON(
|
||||
http.StatusOK,
|
||||
new(entity.ServerInfo))
|
||||
}
|
||||
Reference in New Issue
Block a user