本文整理汇总了Golang中Logger.Fatal函数的典型用法代码示例。如果您正苦于以下问题:Golang Fatal函数的具体用法?Golang Fatal怎么用?Golang Fatal使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Fatal函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: getOrderBook
func (w *Huobi) getOrderBook(symbol string) (ret bool, hbOrderBook OrderBook) {
// init to false
ret = false
var huobisymbol string
if symbol == "btc_cny" {
huobisymbol = "huobibtccny"
} else {
huobisymbol = "huobiltccny"
logger.Fatal("huobi does not support LTC by now, wait for huobi provide it.", huobisymbol)
return
}
rnd := util.RandomString(20)
now := time.Now().UnixNano() / 1000000
req, err := http.NewRequest("GET", fmt.Sprintf(Config["hb_trade_detail"], rnd, now, now), nil)
if err != nil {
logger.Fatal(err)
return
}
req.Header.Set("Referer", Config["base_url"])
req.Header.Add("Connection", "keep-alive")
req.Header.Add("User-Agent", "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36")
req.Header.Add("Accept-Encoding", "identity")
resp, err := http.DefaultClient.Do(req)
if err != nil {
logger.Traceln(err)
logger.Traceln(req)
logger.Traceln(resp)
return
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
logger.Errorf("HTTP returned status %v", resp)
return
}
var body string
contentEncoding := resp.Header.Get("Content-Encoding")
logger.Tracef("HTTP returned Content-Encoding %s", contentEncoding)
switch contentEncoding {
case "gzip":
body = util.DumpGZIP(resp.Body)
default:
bodyByte, err := ioutil.ReadAll(resp.Body)
if err != nil {
logger.Errorln("read the http stream failed")
return
} else {
body = string(bodyByte)
ioutil.WriteFile("cache/OrderBook.json", bodyByte, 0644)
}
}
return w.analyzeOrderBook(body)
}
示例2: Get_account_info
func (w *HuobiTrade) Get_account_info() (account_info Account_info, ret bool) {
pParams := make(map[string]string)
pParams["method"] = "get_account_info"
pParams["access_key"] = w.access_key
now := time.Now().Unix()
pParams["created"] = strconv.FormatInt(now, 10)
pParams["sign"] = w.createSign(pParams)
ret = true
body, err := w.httpRequest(pParams)
if err != nil {
ret = false
return
}
_, ret = w.check_json_result(body)
if ret == false {
return
}
doc := json.NewDecoder(strings.NewReader(body))
if err := doc.Decode(&account_info); err == io.EOF {
logger.Fatal(err)
} else if err != nil {
logger.Fatal(err)
}
logger.Traceln(account_info)
return
}
示例3: GetAccount
func (w *BitvcTrade) GetAccount() (account_info Account_info, ret bool) {
pParams := make(map[string]string)
ret = true
body, err := w.httpRequest(pParams)
if err != nil {
ret = false
return
}
_, ret = w.check_json_result(body)
if ret == false {
return
}
doc := json.NewDecoder(strings.NewReader(body))
if err := doc.Decode(&account_info); err == io.EOF {
logger.Fatal(err)
} else if err != nil {
logger.Fatal(err)
}
logger.Traceln(account_info)
return
}
示例4: GetAccount
/*
{"code":0,"msg":"","ext":{"cny_balance":{"CNY":{"total":340062540230000,"available":340062540230000,"frozen":0},"BTC":{"total":177247000000,"available":177247000000,"frozen":0},"LTC":{"total":0,"available":0,"frozen":0},"now_btc_price":"38380100000000","now_ltc_price":"471500000000","LOAN_CNY":0,"LOAN_BTC":177247000000,"LOAN_LTC":0,"net_asset":340062540230000,"total":1020338298700000},"coin_saving_balance":{"btc_total":"0","ltc_total":"0"}}}
*/
func (w *BitvcTrade) GetAccount() (account_info Account_info, ret bool) {
w.Login()
pParams := make(map[string]string)
ret = true
body, err := w.httpRequest("https://www.bitvc.com/ajax/user_balance", pParams)
if err != nil {
ret = false
return
}
fmt.Println(body)
_, ret = w.check_json_result(body)
if ret == false {
return
}
doc := json.NewDecoder(strings.NewReader(body))
if err := doc.Decode(&account_info); err == io.EOF {
logger.Fatal(err)
} else if err != nil {
logger.Fatal(err)
}
logger.Traceln(account_info)
return
}
示例5: AnalyzeKLinePeroid
func (w *Huobi) AnalyzeKLinePeroid(symbol string, peroid int) (ret bool, records []Record) {
ret = false
var huobisymbol string
if symbol == "btc_cny" {
huobisymbol = "huobibtccny"
} else {
huobisymbol = "huobiltccny"
logger.Fatal("huobi does not support LTC by now, wait for huobi provide it.", huobisymbol)
return
}
req, err := http.NewRequest("GET", fmt.Sprintf(Config["hb_kline_url"], peroid), nil)
if err != nil {
logger.Fatal(err)
return
}
req.Header.Set("Referer", Config["hb_base_url"])
req.Header.Add("Connection", "keep-alive")
req.Header.Add("User-Agent", "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36")
logger.Traceln(req)
c := util.NewTimeoutClient()
logger.Tracef("HTTP req begin AnalyzeKLinePeroid")
resp, err := c.Do(req)
logger.Tracef("HTTP req end AnalyzeKLinePeroid")
if err != nil {
logger.Traceln(err)
return
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
logger.Tracef("HTTP returned status %v", resp)
return
}
var body string
contentEncoding := resp.Header.Get("Content-Encoding")
logger.Tracef("HTTP returned Content-Encoding %s", contentEncoding)
logger.Traceln(resp.Header.Get("Content-Type"))
switch contentEncoding {
case "gzip":
body = util.DumpGZIP(resp.Body)
default:
bodyByte, err := ioutil.ReadAll(resp.Body)
if err != nil {
logger.Errorln("read the http stream failed")
return
} else {
body = string(bodyByte)
}
}
ioutil.WriteFile(fmt.Sprintf("cache/hbKLine_%03d.data", peroid), []byte(body), 0644)
return analyzePeroidLine(fmt.Sprintf("cache/hbKLine_%03d.data", peroid))
}
示例6: httpRequest
func (w *HuobiTrade) httpRequest(pParams map[string]string) (string, error) {
v := url.Values{}
for key, val := range pParams {
v.Add(key, val)
}
req, err := http.NewRequest("POST", Config["api_url"], strings.NewReader(v.Encode()))
if err != nil {
logger.Fatal(err)
return "", err
}
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
req.Header.Set("Referer", "https://www.huobi.com/")
req.Header.Add("Connection", "keep-alive")
req.Header.Add("User-Agent", "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36")
logger.Traceln(req)
c := util.NewTimeoutClient()
logger.Tracef("HTTP req begin HuobiTrade")
resp, err := c.Do(req)
logger.Tracef("HTTP req end HuobiTrade")
if err != nil {
logger.Fatal(err)
return "", err
}
defer resp.Body.Close()
logger.Tracef("api_url resp StatusCode=%v", resp.StatusCode)
logger.Tracef("api_url resp=%v", resp)
if resp.StatusCode == 200 {
var body string
contentEncoding := resp.Header.Get("Content-Encoding")
logger.Tracef("HTTP returned Content-Encoding %s", contentEncoding)
logger.Traceln(resp.Header.Get("Content-Type"))
switch contentEncoding {
case "gzip":
body = DumpGZIP(resp.Body)
default:
bodyByte, _ := ioutil.ReadAll(resp.Body)
body = string(bodyByte)
ioutil.WriteFile("cache/api_url.json", bodyByte, 0644)
}
logger.Traceln(body)
return body, nil
} else {
logger.Tracef("resp %v", resp)
}
return "", nil
}
示例7: parseMinuteCSV
func parseMinuteCSV(filename string) (MinuteRecords []MinuteRecord) {
// convert to standard csv file
data2csv(filename, 3)
file, err := os.Open(filename + ".csv")
if err != nil {
fmt.Println("ParseMinuteCSV Error:", err)
return
}
defer file.Close()
reader := csv.NewReader(file)
/*
record, err := reader.ReadAll()
fmt.Println(record)
return
*/
for {
record, err := reader.Read()
if err == io.EOF {
break
} else if err != nil {
fmt.Println("Error:", err)
return
}
if len(record) < 4 {
fmt.Println("Error:", "record is zero, maybe it is not a cvs format!!!")
return
}
var minRecord MinuteRecord
minRecord.Time = record[0]
minRecord.Price, err = strconv.ParseFloat(record[1], 64)
if err != nil {
logger.Fatalln(record)
logger.Fatal("ParseMinuteCSV item price is not number")
}
minRecord.Volumn, err = strconv.ParseFloat(record[2], 64)
if err != nil {
logger.Fatal("ParseMinuteCSV item Volumn is not number")
}
minRecord.Amount, err = strconv.ParseFloat(record[3], 64)
if err != nil {
logger.Fatal("ParseMinuteCSV item Amount is not number")
}
MinuteRecords = append(MinuteRecords, minRecord)
}
return
}
示例8: Cancel_order
func (w *BitvcTrade) Cancel_order(id string) bool {
pParams := make(map[string]string)
body, err := w.httpRequest(pParams)
if err != nil {
return false
}
_, ret := w.check_json_result(body)
if ret == false {
return false
}
doc := json.NewDecoder(strings.NewReader(body))
type Msg struct {
Result string
}
var m Msg
if err := doc.Decode(&m); err == io.EOF {
logger.Traceln(err)
} else if err != nil {
logger.Fatal(err)
}
logger.Traceln(m)
if m.Result == "success" {
return true
} else {
return false
}
}
示例9: doTrade
func (w *BitvcTrade) doTrade(method, price, amount string) int {
pParams := make(map[string]string)
body, err := w.httpRequest(pParams)
if err != nil {
return 0
}
_, ret := w.check_json_result(body)
if ret == false {
return 0
}
doc := json.NewDecoder(strings.NewReader(body))
type Msg struct {
Result string
Id int
}
var m Msg
if err := doc.Decode(&m); err == io.EOF {
logger.Traceln(err)
} else if err != nil {
logger.Fatal(err)
}
logger.Infoln(m)
if m.Result == "success" {
return m.Id
} else {
return 0
}
}
示例10: handleStaging
func handleStaging(bbs bbs.StagerBBS, natsClient yagnats.NATSClient) {
var task uint64
natsClient.SubscribeWithQueue("stage", "stager", func(msg *yagnats.Message) {
var message stagingMessage
err := json.Unmarshal(msg.Payload, &message)
if err != nil {
logger.Fatal("staging-request.invalid", map[string]interface{}{
"error": err.Error(),
"payload": string(msg.Payload),
})
return
}
for i := 0; i < message.Count; i++ {
guid := atomic.AddUint64(&task, 1)
task := &models.Task{
Guid: fmt.Sprintf("task-%d", guid),
MemoryMB: message.MemoryMB,
ReplyTo: msg.ReplyTo,
}
logger.Info("staging-request.desire", map[string]interface{}{
"task": task,
})
go bbs.DesireTask(task)
}
})
}
示例11: Get_order
func (w *OkcoinTrade) Get_order(symbol, order_id string) (m OrderTable, ret bool) {
api_url := "https://www.okcoin.com/api/getorder.do"
pParams := make(map[string]string)
pParams["partner"] = w.partner
pParams["symbol"] = symbol
pParams["order_id"] = order_id
ret = true
body, err := w.httpRequest(api_url, pParams)
if err != nil {
ret = false
return
}
_, ret = w.check_json_result(body)
if ret == false {
return
}
doc := json.NewDecoder(strings.NewReader(body))
if err := doc.Decode(&m); err == io.EOF {
logger.Traceln(err)
} else if err != nil {
logger.Fatal(err)
}
logger.Traceln(m)
return
}
示例12: Get_orders
func (w *BitvcTrade) Get_orders() (ret bool, m []HBOrderItem) {
pParams := make(map[string]string)
ret = true
body, err := w.httpRequest(pParams)
if err != nil {
ret = false
return
}
_, ret = w.check_json_result(body)
if ret == false {
return
}
doc := json.NewDecoder(strings.NewReader(body))
if err := doc.Decode(&m); err == io.EOF {
logger.Traceln(err)
} else if err != nil {
logger.Fatal(err)
}
logger.Traceln(m)
return
}
示例13: check_json_result
func (w *OkcoinTrade) check_json_result(body string) (errorMsg ErrorMsg, ret bool) {
if strings.Contains(body, "result") != true {
ret = false
return
}
doc := json.NewDecoder(strings.NewReader(body))
if err := doc.Decode(&errorMsg); err == io.EOF {
logger.Traceln(err)
} else if err != nil {
logger.Fatal(err)
logger.Fatalln(body)
}
if errorMsg.Result != true {
logger.Errorln(errorMsg)
SetLastError(errorMsg.ErrorCode)
ret = false
return
}
ret = true
return
}
示例14: TradeKLinePeroid
func (w *Huobi) TradeKLinePeroid(peroid int) (ret bool) {
req, err := http.NewRequest("GET", fmt.Sprintf(Config["trade_kline_url"], peroid, rand.Float64()), nil)
if err != nil {
logger.Fatal(err)
return false
}
req.Header.Set("Referer", Config["trade_flash_url"])
req.Header.Add("Connection", "keep-alive")
req.Header.Add("User-Agent", "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36")
logger.Traceln(req)
if w.client == nil {
w.client = &http.Client{nil, nil, nil}
}
resp, err := w.client.Do(req)
if err != nil {
logger.Errorln(err)
return false
}
defer resp.Body.Close()
if resp.StatusCode == 200 {
var body string
contentEncoding := resp.Header.Get("Content-Encoding")
logger.Tracef("HTTP returned Content-Encoding %s", contentEncoding)
switch contentEncoding {
case "gzip":
body = DumpGZIP(resp.Body)
default:
bodyByte, err := ioutil.ReadAll(resp.Body)
if err != nil {
logger.Errorln("read the http stream failed")
return false
} else {
body = string(bodyByte)
ioutil.WriteFile(fmt.Sprintf("cache/TradeKLine_%03d.data", peroid), bodyByte, os.ModeAppend)
}
}
logger.Traceln(resp.Header.Get("Content-Type"))
ret := strings.Contains(body, "您需要登录才能继续")
if ret {
logger.Traceln("您需要登录才能继续")
return false
} else {
return w.AnalyzePeroidLine(fmt.Sprintf("cache/TradeKLine_%03d.data", peroid), body)
}
} else {
logger.Tracef("HTTP returned status %v", resp)
}
return false
}
示例15: getMonitorPath
func getMonitorPath() (mpath string, err error) {
cfg, err := goconfig.LoadConfigFile("./etc/live_box.conf")
if err != nil {
logger.Fatal("load config file live_box.conf failed!")
return "", err
}
return cfg.GetValue("taskGenerator", "video_path")
}