当前位置: 首页>>代码示例>>Golang>>正文


Golang gos.DoError函数代码示例

本文整理汇总了Golang中github.com/kere/gos.DoError函数的典型用法代码示例。如果您正苦于以下问题:Golang DoError函数的具体用法?Golang DoError怎么用?Golang DoError使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了DoError函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: FetchStockData

// FetchStockData 抓取数据
func FetchStockData(code string) (*StockIndustry, *StockICB, error) {
	// http://stockData.stock.hexun.com/600028.shtml
	formt := "http://stockData.stock.hexun.com/%s.shtml"
	resp, err := wget.Get(fmt.Sprintf(formt, code))
	if err != nil {
		return nil, nil, gos.DoError(err)
	}

	doc, err := goquery.NewDocumentFromResponse(resp)
	if err != nil {
		return nil, nil, gos.DoError(err)
	}

	tr := doc.Find("#list3 table.box6 tr")

	stockIndustry := &StockIndustry{}
	stockICB := &StockICB{}

	stockIndustry.Name, err = iconv.ConvertString(tr.Eq(7).Find("td").Eq(1).Text(), "gb2312", "utf-8")
	if err != nil {
		return nil, nil, gos.DoError(err)
	}

	stockICB.Name, err = iconv.ConvertString(tr.Eq(8).Find("td").Eq(1).Text(), "gb2312", "utf-8")
	if err != nil {
		return nil, nil, gos.DoError(err)
	}

	return stockIndustry, stockICB, nil
}
开发者ID:jiorry,项目名称:gotock,代码行数:31,代码来源:stockdata.go

示例2: GetRzrqStockData

// GetRzrqStockData 抓取数据
func GetRzrqStockData(code string) ([]*RzrqStockData, error) {
	if isStockCached(code) {
		log.App.Info("rzrq stock cached", code)
		return stockDataCached[code], nil
	}

	src, err := FetchRzrqStockData(code, 1)
	if err != nil {
		return nil, gos.DoError(err)
	}

	v := &RzrqStockJSONData{}
	// [{stats:false}]
	if len(src) == 15 && string(src) == "[{stats:false}]" {
		return nil, fmt.Errorf("您所查找的股票代码 %s 不存在", code)
	}

	if err = json.Unmarshal(src, &v); err != nil {
		return nil, gos.DoError(err)
	}
	var dataSet []*RzrqStockData
	dataSet, err = v.ParseSumData()
	if err != nil {
		return nil, err
	}

	stockDataCached[code] = dataSet
	return dataSet, err
}
开发者ID:jiorry,项目名称:gotock,代码行数:30,代码来源:rzrq_stock.go

示例3: Post

func Post(url string, val url.Values) (*http.Response, error) {
	resp, err := http.PostForm(url, val)
	if err != nil {
		return nil, gos.DoError(err)
	}

	if resp.StatusCode != 200 {
		return resp, gos.DoError(fmt.Sprintf("Post failed:%d", resp.StatusCode))
	}

	return resp, nil
}
开发者ID:jiorry,项目名称:gotock,代码行数:12,代码来源:wget.go

示例4: GetBody

func GetBody(url string) ([]byte, error) {
	resp, err := Get(url)
	if err != nil {
		return nil, gos.DoError(err)
	}

	defer resp.Body.Close()

	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return nil, gos.DoError(err)
	}

	return body, nil
}
开发者ID:jiorry,项目名称:gotock,代码行数:15,代码来源:wget.go

示例5: PostBody

func PostBody(url string, val url.Values) ([]byte, error) {
	resp, err := Post(url, val)
	if err != nil {
		return nil, gos.DoError(err)
	}

	defer resp.Body.Close()

	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return nil, gos.DoError(err)
	}

	return body, nil
}
开发者ID:jiorry,项目名称:gotock,代码行数:15,代码来源:wget.go

示例6: FillPingGuData

// FillStockData 抓取数据
func FillPingGuData() {
	// http://stockData.stock.hexun.com/600028.shtml
	var stockID int64
	var pinggu *PingGuStruct
	var err error

	ist := db.NewInsertBuilder("pinggu")
	exists := db.NewExistsBuilder("pinggu")

	dataset, _ := db.NewQueryBuilder("stock").Select("id,code,ctype").Limit(0).Query()

	for _, data := range dataset {
		if exists.Where("stock_id=? and date=?", data.GetInt64("id"), util.StockQuarter()).Exists() {
			continue
		}
		pinggu, err = FetchPingGuData(data.GetString("code"))
		if err != nil {
			gos.DoError(err)
			continue
		}
		stockID = data.GetInt64("id")
		for _, row := range pinggu.Content {
			row.StockID = stockID
			ist.Insert(row)
		}
		fmt.Println("insert ", data.GetString("code"))
		time.Sleep(1 * time.Second)
	}
}
开发者ID:jiorry,项目名称:gotock,代码行数:30,代码来源:pinggu.go

示例7: ParseSumData

// ParseSumData 解析两市汇总信息
func (r RzrqStockJSONData) ParseSumData() ([]*RzrqStockData, error) {
	if len(r) == 0 {
		return nil, nil
	}
	var err error
	var dataSet = make([]*RzrqStockData, 0)

	var tmp []string
	var itemData *RzrqStockData
	var x float64
	var val reflect.Value
	var mapping *stockDataMapping
	var isFirst = true

	for _, item := range r {
		tmp = strings.Split(item, ",")

		itemData = &RzrqStockData{}
		itemData.Date, err = time.Parse("2006/1/2", tmp[4])
		if err != nil {
			return nil, gos.DoError(err)
		}

		if isFirst {
			itemData.Code = tmp[0]
			itemData.Name = tmp[2]
			isFirst = false
		}

		val = reflect.ValueOf(itemData).Elem()
		for _, mapping = range rzrqStockDataMapping {
			if tmp[mapping.Index] == "" || tmp[mapping.Index] == "-" {
				continue
			}

			if x, err = strconv.ParseFloat(tmp[mapping.Index], 64); err != nil {
				return nil, gos.DoError(err)
			}

			val.FieldByName(mapping.Name).SetFloat(x)
		}

		dataSet = append(dataSet, itemData)
	}

	return dataSet, nil
}
开发者ID:jiorry,项目名称:gotock,代码行数:48,代码来源:rzrq_stock.go

示例8: FillGgcg

// FillYyb 抓取数据
func FillGgcg() error {
	v, err := FetchGgcg(1)
	if err != nil {
		return err
	}

	var item *ggcgVO
	l := v.Parse()
	// create
	for _, item = range l {
		item.Init(item)
		item.Create()

		if err != nil {
			gos.DoError(err)
		}
	}
	time.Sleep(1 * time.Second)

	pages := v.Pages
	if pages > 20 {
		pages = 20
	}

	for i := 2; i < pages+1; i++ {
		v, err = FetchGgcg(i)
		if err != nil {
			return err
		}

		l = v.Parse()
		for _, item = range l {
			item.Init(item)
			item.Create()

			if err != nil {
				gos.DoError(err)
			}
		}

		time.Sleep(1 * time.Second)
	}

	return err
}
开发者ID:jiorry,项目名称:gotock,代码行数:46,代码来源:ggcg.go

示例9: Get

// Wget 抓取数据
func Get(url string) (*http.Response, error) {
	client := &http.Client{}
	req, err := http.NewRequest("GET", url, nil)
	req.Header.Add("User-Agent", `Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.157 Safari/537.36`)
	resp, err := client.Do(req)

	if err != nil {
		return nil, gos.DoError("error:", err)
	} else if resp.Body == nil {
		return nil, gos.DoError("error: resp.Body is empty")
	}

	if resp.StatusCode != 200 {
		return resp, gos.DoError(fmt.Sprintf("Get failed:%d", resp.StatusCode))
	}
	// var OKPJKmpr={pages:0,data:[{stats:false}]}
	return resp, nil
}
开发者ID:jiorry,项目名称:gotock,代码行数:19,代码来源:wget.go

示例10: GetRzrqSumData

// RzrqSumData 抓取数据
func GetRzrqSumData() ([]*RzrqSumItemData, error) {
	if isCached() {
		log.App.Info("rzrq sum cached")
		return sumdataCached, nil
	}

	src, err := FetchRzrqSumData(1)
	if err != nil {
		return nil, gos.DoError(err)
	}
	v := &RzrqSumJSONData{}
	if err = json.Unmarshal(src, &v); err != nil {
		return nil, gos.DoError(err)
	}

	sumdataCached, err = v.ParseSumData()
	return sumdataCached, err
}
开发者ID:jiorry,项目名称:gotock,代码行数:19,代码来源:rzrq_sum.go

示例11: main

func main() {
	data, err := cninfo.FetchFinancialData("600718", "2015-09-30")

	if err != nil {
		gos.DoError(err).LogError()
		fmt.Println(err)
		return
	}

	fmt.Println(data)
}
开发者ID:jiorry,项目名称:gotock,代码行数:11,代码来源:financial.go

示例12: ParseSumData

// ParseSumData 解析两市汇总信息
func (r RzrqSumJSONData) ParseSumData() ([]*RzrqSumItemData, error) {
	if len(r) == 0 {
		return nil, nil
	}
	var err error
	var dataSet = make([]*RzrqSumItemData, 0)

	var tmp []string
	var itemData *RzrqSumItemData
	var x int64
	var val reflect.Value

	for _, item := range r {
		tmp = strings.Split(item, ",")
		if len(tmp) != 13 {
			return nil, fmt.Errorf("parse data error")
		}

		itemData = &RzrqSumItemData{}
		itemData.Date, err = time.Parse("2006-01-02", tmp[0])
		if err != nil {
			return nil, gos.DoError(err)
		}

		val = reflect.ValueOf(itemData).Elem()
		for _, mapping := range rzrqSumDataMapping {
			if tmp[mapping.Index] == "-" || tmp[mapping.Index] == "" {
				val.FieldByName(mapping.Name).SetInt(-1)
				continue
			}

			if x, err = util.Str2Int64(tmp[mapping.Index]); err != nil {
				return nil, gos.DoError(err)
			}
			val.FieldByName(mapping.Name).SetInt(x)
		}
		dataSet = append(dataSet, itemData)
	}

	return dataSet, nil
}
开发者ID:jiorry,项目名称:gotock,代码行数:42,代码来源:rzrq_sum.go

示例13: FetchPingGuData

// FetchPingGuData 抓取行业评估数据
func FetchPingGuData(code string) (*PingGuStruct, error) {
	// http://stockData.stock.hexun.com/600028.shtml
	now := gos.NowInLocation()
	formt := "http://pinggu.stock.hexun.com/DataProvider/StockFinanceNewFlash.ashx?&code=%s&s=%d"
	body, err := wget.GetBody(fmt.Sprintf(formt, code, now.Unix()))
	if err != nil {
		return nil, gos.DoError(err)
	}

	v := &PingGuStruct{}
	err = xml.Unmarshal(body, v)

	if err != nil {
		return nil, gos.DoError(err)
	}

	quarter := util.StockQuarter()
	for _, item := range v.Content {
		item.Date = quarter
		switch item.Name {
		case "综合能力":
			item.Itype = 1
		case "盈利能力":
			item.Itype = 2
		case "偿债能力":
			item.Itype = 3
		case "成长能力":
			item.Itype = 4
		case "资产经营":
			item.Itype = 5
		case "市场表现":
			item.Itype = 6
		case "投资收益":
			item.Itype = 7
		}
	}

	return v, nil
}
开发者ID:jiorry,项目名称:gotock,代码行数:40,代码来源:pinggu.go

示例14: FetchRzrqSumData

// FetchRzrqSumData 抓取数据
func FetchRzrqSumData(page int) ([]byte, error) {
	st := gos.NowInLocation().Unix() / 30
	formt := "http://datainterface.eastmoney.com/EM_DataCenter/JS.aspx?type=FD&sty=%s&st=0&sr=1&p=%d&ps=50&js=var%%20ruOtumOo={pages:(pc),data:[(x)]}&rt=%d"

	url := fmt.Sprintf(formt, "SHSZHSSUM", page, st)

	body, err := wget.GetBody(url)
	if err != nil {
		return nil, gos.DoError(err)
	}

	return body[bytes.Index(body, []byte("[")) : len(body)-1], nil
}
开发者ID:jiorry,项目名称:gotock,代码行数:14,代码来源:rzrq_sum.go

示例15: FillStockData

// FillStockData 抓取数据
func FillStockData() {
	// http://stockData.stock.hexun.com/600028.shtml
	upd := db.NewUpdateBuilder("stock")
	ist := db.NewInsertBuilder("")
	q := db.NewQueryBuilder("")
	dataset, _ := db.NewQueryBuilder("stock").Select("id,code,ctype").Limit(0).Query()

	for _, data := range dataset {
		if data.GetInt("industry_id") == 0 || data.GetInt("icb_id") == 0 {
			industry, icb, err := FetchStockData(data.GetString("code"))
			if err != nil {
				gos.DoError(err)
				continue
			}

			if data.GetInt("industry_id") == 0 {
				ist.Table("industry").Insert(industry)
				row, err := q.Table("industry").Where("name=?", industry.Name).QueryOne()
				if err != nil {
					gos.DoError(err)
				} else if !row.Empty() {
					upd.Where("id=?", data.GetInt64("id")).Update(db.DataRow{"industry_id": row.GetInt64("id")})
				}
			}

			if data.GetInt("icb_id") == 0 {
				ist.Table("icb").Insert(icb)
				row, err := q.Table("icb").Where("name=?", icb.Name).QueryOne()
				if err != nil {
					gos.DoError(err)
				} else if !row.Empty() {
					upd.Where("id=?", data.GetInt64("id")).Update(db.DataRow{"icb_id": row.GetInt64("id")})
				}
			}
		}

	}
}
开发者ID:jiorry,项目名称:gotock,代码行数:39,代码来源:stockdata.go


注:本文中的github.com/kere/gos.DoError函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。