示例#1
0
func (this PackJesgooResponseModule) Run(inner_data *context.Context) (err error) {

	var temp_response jesgoo_interface.SellerResponse
	temp_response.Success = new(bool)
	*temp_response.Success = true
	temp_response.SearchId = new(string)
	*temp_response.SearchId = inner_data.Searchid
	temp_response.Ads = make([]*jesgoo_interface.SellerResponse_Ad, 0)
	need_ad := inner_data.Req.AdSlot.Capacity
	ad_num := len(inner_data.Resp.Ads)
	var pack_num int32
	if int32(need_ad) < int32(ad_num) {
		pack_num = int32(need_ad)
	} else {
		pack_num = int32(ad_num)
	}
	utils.DebugLog.Write("pack_num is %d", pack_num)
	var i int32
	for i = 0; i < pack_num; i++ {
		var temp_ad jesgoo_interface.SellerResponse_Ad
		temp_ad.AdslotId = new(string)
		*temp_ad.AdslotId = inner_data.Req.AdSlot.Slotid
		temp_ad.MaterialType = new(jesgoo_interface.SellerResponse_Ad_MaterialType)
		switch inner_data.Req.AdSlot.AdSlotType {
		case context.AdSlotType_BANNER:
			*temp_ad.MaterialType = jesgoo_interface.SellerResponse_Ad_DYNAMIC
			temp_ad.HtmlSnippet = make([]byte, 0)
			temp_ad.HtmlSnippet = inner_data.Resp.Ads[i].HtmlSnippet.Bytes()
		case context.AdSlotType_INITIALIZATION:
			*temp_ad.MaterialType = jesgoo_interface.SellerResponse_Ad_NATIVE
			err = this.pack_native_ad(&temp_ad, &inner_data.Resp.Ads[i])
		}
		temp_response.Ads = append(temp_response.Ads, &temp_ad)
	}
	inner_data.RespBody, err = proto.Marshal(&temp_response)
	return
}
示例#2
0
func run() {

	var req_body jesgoo_interface.SellerRequest
	var resp_body jesgoo_interface.SellerResponse
	var media_tmp jesgoo_interface.Media
	media_tmp.Id = new(string)
	*media_tmp.Id = "123"
	media_tmp.ChannelId = new(string)
	*media_tmp.ChannelId = "123"
	media_tmp.Type = new(jesgoo_interface.MediaType)
	*media_tmp.Type = jesgoo_interface.MediaType_APP
	req_body.Media = new(jesgoo_interface.Media)
	*req_body.Media = media_tmp
	var deviceid_tmp jesgoo_interface.DeviceID
	deviceid_tmp.Type = new(jesgoo_interface.DeviceIDType)
	*deviceid_tmp.Type = jesgoo_interface.DeviceIDType_IMEI
	deviceid_tmp.Id = []byte("351806037915050")
	//	deviceid_tmp.Id = make([]byte, 0)
	//	*deviceid_tmp.Id = []byte("351806037915050")
	//	deviceid_tmp.Id = append(deviceid_tmp.Id, []byte("351806037915050"))
	var device_tmp jesgoo_interface.Device
	device_tmp.Ids = make([]*jesgoo_interface.DeviceID, 0)
	device_tmp.Ids = append(device_tmp.Ids, &deviceid_tmp)
	device_tmp.Type = new(jesgoo_interface.DeviceType)
	*device_tmp.Type = jesgoo_interface.DeviceType_DEV_PHONE
	device_tmp.OsType = new(jesgoo_interface.OSType)
	*device_tmp.OsType = jesgoo_interface.OSType_ANDROID
	device_tmp.OsVersion = new(jesgoo_interface.Version)
	device_tmp.OsVersion.Major = new(uint32)
	*device_tmp.OsVersion.Major = 1
	req_body.Device = new(jesgoo_interface.Device)
	*req_body.Device = device_tmp
	req_body.Network = new(jesgoo_interface.Network)
	req_body.Network.Ip = new(string)
	*req_body.Network.Ip = "61.171.44.61"
	req_body.Adslots = make([]*jesgoo_interface.AdSlot, 0)
	var adslot jesgoo_interface.AdSlot
	adslot.Id = new(string)
	*adslot.Id = "123"
	adslot.Type = new(jesgoo_interface.AdSlotType)
	*adslot.Type = jesgoo_interface.AdSlotType_RECOMMEND
	adslot.Size = new(jesgoo_interface.Size)
	adslot.Size.Width = new(uint32)
	*adslot.Size.Width = 0
	adslot.Size.Height = new(uint32)
	*adslot.Size.Height = 0
	req_body.Adslots = append(req_body.Adslots, &adslot)

	var client_tmp jesgoo_interface.Client
	client_tmp.Type = new(jesgoo_interface.ClientType)
	*client_tmp.Type = jesgoo_interface.ClientType_NATIVESDK
	client_tmp.Version = new(jesgoo_interface.Version)
	client_tmp.Version.Major = new(uint32)
	*client_tmp.Version.Major = 1
	req_body.Client = new(jesgoo_interface.Client)
	*req_body.Client = client_tmp

	fmt.Println(req_body)
	b, err := proto.Marshal(&req_body)
	if err != nil {
		fmt.Println("format err:", err)
	}

	body := bytes.NewBuffer([]byte(b))
	res, err := http.Post("http://localhost:8081/v1/protobuf", "application/json;charset=utf-8", body)
	if err != nil {
		log.Fatal(err)
		return
	}
	fmt.Printf("response header is: %d\n", res.StatusCode)
	result, err := ioutil.ReadAll(res.Body)
	res.Body.Close()
	if err != nil {
		log.Fatal(err)
		return
	}
	err = proto.Unmarshal(result, &resp_body)
	fmt.Println("response is: " + resp_body.String())
	w.Done()
}