• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang gos.DoError函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: DeleteByName

func (u *ImageModel) DeleteByName(name string) (bool, error) {
	img, err := db.NewQueryBuilder(u.Table()).Where("name=?", name).QueryOne()
	if err != nil {
		return false, err
	}
	if img.Empty() {
		return false, gos.DoError("没有找到相应的记录")
	}
	date := img.GetTime("created_at").Format("20060102")
	filename := fmt.Sprint(name, img.GetString("ext"))
	os.Remove(path.Join(gos.HomeDir, "/webroot/uploads/pictures", date, filename))

	_, err = db.NewDeleteBuilder(u.Table()).Where("id=?", img.GetInt64("id")).Delete()

	return true, err
}
开发者ID:kere,项目名称:mdwriter,代码行数:16,代码来源:image_model.go


示例17: GetByCid

func (a *ArticleApi) GetByCid(cid string) (db.DataRow, error) {
	q := db.NewQueryBuilder("articles").Select("cid,user_id,title,html,status,created_at,updated_at")
	row, err := q.Where("cid=?", cid).QueryOne()
	if err != nil {
		return nil, err
	}
	if row.Empty() {
		return nil, gos.DoError("没有找到相应的记录")
	}
	row = row.Bytes2String()
	user, err := user.NewUserModel().GetById(row.GetInt64("user_id"))
	if err != nil {
		return nil, err
	}
	user = user.Bytes2String()

	row["user"] = user
	return row, err
}
开发者ID:kere,项目名称:mdwriter,代码行数:19,代码来源:article.go


示例18: GetByCid

func (a *WriterApi) GetByCid(cid string) (db.DataRow, error) {
	q := db.NewQueryBuilder("articles").Select("id,cid,user_id,title,body,status,created_at,updated_at")
	row, err := q.Where("cid=?", cid).QueryOne()
	if err != nil {
		return nil, err
	}
	if row.Empty() {
		return nil, gos.DoError("没有找到相应的记录")
	}

	row = row.Bytes2String()

	q1 := db.NewQueryBuilder("images").Select("name,ext,to_char(created_at, 'YYYYMMDD') as date")
	images, err := q1.Where("article_id=?", row.GetInt64("id")).Query()
	if err != nil {
		return nil, err
	}
	row["images"] = images.Bytes2String()
	return row, err
}
开发者ID:kere,项目名称:mdwriter,代码行数:20,代码来源:writer.go


示例19: GetHgtAmount

// http://datainterface.eastmoney.com/EM_DataCenter/JS.aspx?type=SHT&sty=SHTTMYE&rt=0.6341747129336
// curl "http://datainterface.eastmoney.com/EM_DataCenter/JS.aspx?type=SHT&sty=SHTTMYE&rt=0.6341747129336" -H "Pragma: no-cache" -H "Accept-Encoding: gzip, deflate, sdch" -H "Accept-Language: en-US,en;q=0.8,zh-CN;q=0.6,zh;q=0.4,zh-TW;q=0.2" -H "User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.157 Safari/537.36" -H "Accept: */*" -H "Referer: http://data.eastmoney.com/bkzj/hgt.html" -H "X-Requested-With: ShockwaveFlash/18.0.0.232" -H "Cookie: HAList=f-0-000003-B"%"u80A1"%"u6307"%"u6570; pgv_pvi=3511567662; pgv_info=ssi=s7100762258" -H "Connection: keep-alive" -H "Cache-Control: no-cache" --compressed
// RzrqSumData 抓取数据
func GetHgtAmount() ([]*HgtAmount, error) {
	r := rand.New(rand.NewSource(99))
	formt := "http://datainterface.eastmoney.com/EM_DataCenter/JS.aspx?type=SHT&sty=SHTTMYE&rt=%v"

	body, err := wget.GetBody(fmt.Sprintf(formt, r.Float64()))
	if err != nil {
		return nil, gos.DoError(err)
	}

	now := gos.NowInLocation()
	arr := bytes.Split(body, []byte("\r\n"))
	var tmp [][]byte
	result := make([]*HgtAmount, len(arr))
	var amountA float64
	var amountB float64
	var date time.Time

	for i, v := range arr {
		tmp = bytes.Split(v, gos.B_SEMICOLON)
		amountA, err = util.Str2Float64(string(tmp[1]))
		if err != nil {
			amountA = 0
		}
		amountB, err = util.Str2Float64(string(tmp[2]))
		if err != nil {
			amountA = 0
		}
		date, err = time.ParseInLocation("2006/1/2 15:04", fmt.Sprint(now.Format("2006/1/2"), " ", string(tmp[0])), gos.GetSite().Location)
		if err != nil {
			date = now
		}
		result[i] = &HgtAmount{
			Date:    date,
			AmountA: amountA,
			AmountB: amountB,
		}
	}
	return result, nil
}
开发者ID:jiorry,项目名称:gotock,代码行数:42,代码来源:hgt.go


示例20: Save

func (a *WriterApi) Save(args util.MapData) (string, error) {
	cid := args.GetString("cid")
	title := args.GetString("title")
	body := args.GetBytes("body")
	images := args.GetStringSlice("images")
	au := a.GetUserAuth()

	var err error

	model := article.NewArticleModel()
	if cid == "" {
		cid, err = model.New(au.UserID(), title, body)
	} else {
		_, err = model.Update(cid, title, body)
	}
	if err != nil {
		return cid, err
	}

	article, _ := db.NewQueryBuilder(model.Table()).Select("id").Where("cid=?", cid).QueryOne()
	if article.Empty() {
		return cid, gos.DoError("没有找到相应的记录")
	}

	count := len(images)
	if count > 0 {
		image := db.DataRow{}
		image["article_id"] = article.GetInt64("id")
		for i := 0; i < count; i++ {
			images[i] = fmt.Sprint("'", images[i], "'")
		}
		db.NewUpdateBuilder("images").
			Where(fmt.Sprint("name in (", strings.Join(images, ","), ")")).
			Update(image)
	}

	return cid, nil
}
开发者ID:kere,项目名称:mdwriter,代码行数:38,代码来源:writer.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang util.MapData类代码示例发布时间:2022-05-23
下一篇:
Golang sanitize.Path函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap