コード例 #1
0
ファイル: person.go プロジェクト: dynastymasra/GoGinThrift
func GetAll(c *gin.Context) {
	protocolFactory := thrift.NewTBinaryProtocolFactoryDefault()
	transportFactory := thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory())
	result, err := service.GetAll(transportFactory, protocolFactory)

	if err != nil {
		m := fmt.Sprintf("%v", err)
		c.JSON(http.StatusExpectationFailed, util.FailResponse(m))
	} else {
		parse := make([]interface{}, len(result))
		for i := range result {
			parse[i] = model.PersonResponse(result[i])
		}
		c.JSON(http.StatusCreated, util.ListResponse("success", "", parse))
	}
}
コード例 #2
0
ファイル: person.go プロジェクト: dynastymasra/GoGinThrift
func Delete(c *gin.Context) {
	protocolFactory := thrift.NewTBinaryProtocolFactoryDefault()
	transportFactory := thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory())

	var json model.Person
	c.BindJSON(&json)
	err := service.Delete(transportFactory, protocolFactory, json.ID)
	if err != nil {
		m := fmt.Sprintf("%v", err)
		c.JSON(http.StatusExpectationFailed, util.FailResponse(m))
	} else {
		parse := map[string]interface{}{
			"person": json,
		}
		c.JSON(http.StatusCreated, util.ObjectResponse("success", "", parse))
	}
}
コード例 #3
0
ファイル: person.go プロジェクト: dynastymasra/GoGinThrift
func Update(c *gin.Context) {
	protocolFactory := thrift.NewTBinaryProtocolFactoryDefault()
	transportFactory := thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory())

	var json model.Person
	c.BindJSON(&json)
	person := model.PersonUpdate(json.ID, json.Identity, json.Firstname, json.Middlename, json.Lastname, json.Address, json.Age, json.Active)
	result, err := service.Update(transportFactory, protocolFactory, person)
	if err != nil {
		m := fmt.Sprintf("%v", err)
		c.JSON(http.StatusExpectationFailed, util.FailResponse(m))
	} else {
		parse := map[string]interface{}{
			"person": model.PersonResponse(result),
		}
		c.JSON(http.StatusCreated, util.ObjectResponse("success", "", parse))
	}
}