Skip to content

Commit

Permalink
add files hosts
Browse files Browse the repository at this point in the history
  • Loading branch information
sjkcdpc committed Jun 12, 2018
1 parent 84a4770 commit 35fa9b8
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 66 deletions.
2 changes: 1 addition & 1 deletion server/hosts/hosts.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ func Start(group *gin.RouterGroup) {
}

for key, value := range handlerFuncList {
group.POST(key, value)
group.GET(key, value)
}
}
69 changes: 7 additions & 62 deletions server/hosts/hosts_items.go
Original file line number Diff line number Diff line change
@@ -1,75 +1,20 @@
package hosts

import (
"github.com/gin-gonic/gin"
"time"
"github.com/mds1455975151/cmdb/utils"
"net/http"

"github.com/gin-gonic/gin"
"github.com/mds1455975151/cmdb/storage"
)

func init() {

handlerFuncList["/hosts"] = hostitem
handlerFuncList["/all"] = hostsall
}

//
// Request Hosts Item
//
type HostsItemReq struct {
// The globalId
//
// Required: true
GlobalId int64 `form:"globalId" json:"globalId" binding:"required"`
}

//
// 应答: 协议返回包
// swagger:response DoBuyItemRsp
// noinspection ALL
type HostsItemRsp struct {
// in: body
Body struct {
// The response code
//
// Required: true
Code int64 `json:"code"`
// The response message
//
// Required: true
Message string `json:"message"`
// The payment sequence to identify the flow.
//
// Required: true
Sequence string `json:"sequence"`
// The response BuyItem
//
// Required: true
BuyItemMidas struct {
//
// ret为0的时候,返回真正购买物品的url的参数,开发者需要把该参数
// 传给sdk跳转到相关页面使用户完成真正的购买动作。
//
UrlParams string `json:"url_params"`
} `json:"buyItemMidas"`
}
}

//
// swagger:route POST /payment/buy_item payment payment_buy_item
//
// Return buy item for the given user:
//
// Consumes:
// - application/json
//
// Produces:
// - application/json
//
// Schemes: http, https
//
// Responses:
// 200: DoBuyItemRsp
func hostitem(c *gin.Context) {

c.JSON(http.StatusOK, resp.Body)
func hostsall(c *gin.Context) {
info := storage.QueryHost(1)
c.JSON(http.StatusOK, info)
}
2 changes: 1 addition & 1 deletion server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,5 @@ func Run() {
"path": basePath,
}).Info("Start cmdb service.")

router.Run()
router.Run(listen)
}
4 changes: 2 additions & 2 deletions storage/model/storage_cmdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import (
"github.com/jinzhu/gorm"
)

type AccountState int
type HostsItem int

const (
Active AccountState = iota
Active HostsItem = iota
InActive
Banned
BanDied
Expand Down
16 changes: 16 additions & 0 deletions storage/storage_cmdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package storage
import (
"github.com/jinzhu/gorm"
"github.com/mds1455975151/cmdb/storage/model"
"github.com/sirupsen/logrus"
)

var dbCmdb *gorm.DB
Expand All @@ -19,3 +20,18 @@ func InitAuthDatabase() {
)
}

func QueryHost(id int64) *model.Hosts {

var data model.Hosts

if err := dbCmdb.Where("id = ?", id).First(&data).Error; err != nil {
logrus.WithFields(logrus.Fields{
"globalId": id,
"error": err.Error(),
}).Error("QueryHost data not found.")

return nil
}

return &data
}

0 comments on commit 35fa9b8

Please sign in to comment.