48 lines
943 B
Go
48 lines
943 B
Go
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))
|
|
}
|