當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。