Skip to content

Commit

Permalink
add files
Browse files Browse the repository at this point in the history
  • Loading branch information
sjkcdpc committed Jun 8, 2018
1 parent 4b76529 commit 84a4770
Show file tree
Hide file tree
Showing 35 changed files with 7,031 additions and 40 deletions.
8 changes: 4 additions & 4 deletions configs/cmdb.default.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
---
mysql:
host: localhost
host: 10.1.16.151
port: 3306
user: root
user: dba
password: '123456'
database: cmdb_go
create_database_if_not_exist: false
database: cmdb
create_database_if_not_exist: true
redis:
host: localhost
port: 6379
Expand Down
48 changes: 12 additions & 36 deletions server/hosts/hosts.go
Original file line number Diff line number Diff line change
@@ -1,51 +1,27 @@
package hosts

import (
"net/http"
"fmt"
//"net/http"
//"fmt"

"github.com/gin-gonic/gin"
//"github.com/sirupsen/logrus"
"github.com/sirupsen/logrus"
)
type hosts struct {
id string `form:"id" json:"id" binding:"required"`
}

func Start(group *gin.RouterGroup) {

group.POST("/", func(c *gin.Context) {
c.String(http.StatusOK, "hello world")
})

var handlerFuncList = make(map[string]gin.HandlerFunc)

//logrus.WithFields(logrus.Fields{
// "n": n,
// "error": err,
//}).Error("exec prefix")

group.GET("/user/:name/*action", func(c *gin.Context) {
name := c.Param("name")
action := c.Param("action")
message := name + " is " + action
c.String(http.StatusOK, message)
})

group.POST("/post", func(c *gin.Context) {
func Start(group *gin.RouterGroup) {

id := c.PostForm("id")
page := c.PostForm("page")
name := c.PostForm("name")
message := c.PostForm("message")
if group == nil {
logrus.Error("admin start failed.")
return
}

fmt.Printf("id: %s; page: %s; name: %s; message: %s", id, page, name, message)
messages := "id:"
messages += id
messages += ",page:"
messages += page
messages += ",name:"
messages += name
messages += ",message:"
messages += message
c.String(http.StatusOK, messages)
})
for key, value := range handlerFuncList {
group.POST(key, value)
}
}
75 changes: 75 additions & 0 deletions server/hosts/hosts_items.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package hosts

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

func init() {

handlerFuncList["/hosts"] = hostitem
}

//
// 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)
}
2 changes: 2 additions & 0 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/sirupsen/logrus"
//"github.com/mds1455975151/cmdb/utils/log"
"github.com/mds1455975151/cmdb/settings"
"github.com/mds1455975151/cmdb/storage"
"github.com/gin-gonic/gin"
"os"
"github.com/mds1455975151/cmdb/server/hosts"
Expand All @@ -24,6 +25,7 @@ func Run() {
logrus.Info(logo)

//log.InitLogger()
storage.Initialize()

var setting = settings.Get("cmdb")
var listen = setting.GetString("gin.listen")
Expand Down
1 change: 1 addition & 0 deletions storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/jinzhu/gorm"
"github.com/sirupsen/logrus"
"github.com/spf13/viper"
_ "github.com/go-sql-driver/mysql"
)

func Initialize() {
Expand Down
89 changes: 89 additions & 0 deletions vendor/github.com/go-sql-driver/mysql/AUTHORS

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 84a4770

Please sign in to comment.