How to use GetErrorMessage method of result Package

Best Gauge code snippet using result.GetErrorMessage

payment.go

Source:payment.go Github

copy

Full Screen

...69 }{}70 err := c.ShouldBindQuery(&req)71 if err != nil {72 log.Errorln(err)73 ret.SetErrCode(ERRCODE_PARAM, GetErrorMessage(ERRCODE_PARAM))74 return75 }76 rsp , err := rpc.InnerService.CurrencyService.CallGetPaySet(&proto.PayRequest{77 Uid: req.Uid,78 })79 if err != nil {80 log.Errorln(err)81 ret.SetErrCode(ERRCODE_UNKNOWN, GetErrorMessage(ERRCODE_UNKNOWN))82 return83 }84 type PaySet struct {85 BankPay uint32 `form:"bank_pay" json:"bank_pay"`86 AliPay uint32 `form:"ali_pay" json:"ali_pay"`87 WeChatPay uint32 `form:"wechat_pay" json:"wechat_pay"`88 PaypalPay uint32 `form:"paypal_pay" json:"paypal_pay"`89 }90 var payset PaySet91 err = json.Unmarshal([]byte(rsp.Data),&payset)92 if err != nil {93 log.Errorln(err)94 ret.SetErrCode(ERRCODE_UNKNOWN, GetErrorMessage(ERRCODE_UNKNOWN))95 return96 }97 ret.SetErrCode(rsp.Code, GetErrorMessage(rsp.Code))98 ret.SetDataSection("setpays", payset)99 return100}101func (*CurrencyGroup) BankPay(c *gin.Context) {102 ret := NewPublciError()103 defer func() {104 c.JSON(http.StatusOK, ret.GetResult())105 }()106 var req BankPay107 err := c.ShouldBind(&req)108 if err != nil {109 log.Errorf(err.Error())110 ret.SetErrCode(ERRCODE_PARAM, err.Error())111 return112 }113 fmt.Printf("%#v\n", req)114 rsp, err := rpc.InnerService.CurrencyService.CallBankPay(&proto.BankPayRequest{115 Uid: req.Uid,116 //Token: req.Token,117 Name: req.Name,118 CardNum: req.CardNum,119 VerifyNum: req.VerifyNum,120 BankName: req.BankName,121 BankInfo: req.BankInfo,122 Verify: req.Verify,123 })124 if err != nil {125 log.Errorf(err.Error())126 ret.SetErrCode(ERRCODE_UNKNOWN, err.Error())127 return128 }129 type RRRBankPay struct {130 Uid uint64 `form:"uid" json:"uid" `131 Name string `form:"name" json:"name" `132 CardNum string `form:"card_num" json:"card_num" `133 BankName string `form:"bank_name" json:"bank_name" `134 BankInfo string `form:"bank_info" json:"bank_info" `135 }136 rrrrbankpay := new(RRRBankPay)137 rrrrbankpay.Uid = req.Uid138 rrrrbankpay.Name = req.Name139 rrrrbankpay.BankInfo = req.BankInfo140 rrrrbankpay.BankName = req.BankName141 ret.SetDataSection("bank_pay", rrrrbankpay)142 ret.SetErrCode(rsp.Code)143 return144}145func (this *CurrencyGroup) GetBankPay(c *gin.Context) {146 ret := NewPublciError()147 defer func() {148 c.JSON(http.StatusOK, ret.GetResult())149 }()150 req := struct {151 Uid uint64 `form:"uid" json:"uid" binding:"required"`152 }{}153 err := c.ShouldBind(&req)154 if err != nil {155 log.Errorf(err.Error())156 ret.SetErrCode(ERRCODE_PARAM, GetErrorMessage(ERRCODE_PARAM))157 return158 }159 rsp, err := rpc.InnerService.CurrencyService.CallGetBankPay(&proto.PayRequest{160 Uid: req.Uid,161 })162 if err != nil {163 log.Errorln(err.Error())164 ret.SetErrCode(ERRCODE_UNKNOWN, GetErrorMessage(ERRCODE_UNKNOWN))165 return166 }167 type RRRBankPay struct {168 Uid uint64 `form:"uid" json:"uid" `169 Name string `form:"name" json:"name" `170 CardNum string `form:"card_num" json:"card_num" `171 BankName string `form:"bank_name" json:"bank_name" `172 BankInfo string `form:"bank_info" json:"bank_info" `173 }174 rrrrbankpay := new(RRRBankPay)175 err = json.Unmarshal([]byte(rsp.Data), rrrrbankpay)176 if err != nil {177 fmt.Println(err.Error())178 }179 ret.SetErrCode(rsp.Code, GetErrorMessage(rsp.Code))180 ret.SetDataSection("bank_pay", rrrrbankpay)181 return182}183func (this *CurrencyGroup) UpdateBankPay(c *gin.Context) {184 ret := NewPublciError()185 defer func() {186 c.JSON(http.StatusOK, ret.GetResult())187 }()188 var req BankPay189 err := c.ShouldBind(&req)190 if err != nil {191 log.Errorf(err.Error())192 ret.SetErrCode(ERRCODE_PARAM, GetErrorMessage(ERRCODE_PARAM))193 return194 }195 rsp, err := rpc.InnerService.CurrencyService.CallUpdateBankPay(&proto.BankPayRequest{196 Uid: req.Uid,197 //Token: req.Token,198 Name: req.Name,199 CardNum: req.CardNum,200 VerifyNum: req.VerifyNum,201 BankName: req.BankName,202 BankInfo: req.BankInfo,203 Verify: req.Verify,204 })205 if err != nil {206 log.Errorln(err.Error())207 ret.SetErrCode(ERRCODE_UNKNOWN, GetErrorMessage(ERRCODE_UNKNOWN))208 return209 } else {210 type RRRBankPay struct {211 Uid uint64 `form:"uid" json:"uid" `212 Name string `form:"name" json:"name" `213 CardNum string `form:"card_num" json:"card_num" `214 BankName string `form:"bank_name" json:"bank_name" `215 BankInfo string `form:"bank_info" json:"bank_info" `216 }217 rrrrbankpay := new(RRRBankPay)218 rrrrbankpay.Uid = req.Uid219 rrrrbankpay.Name = req.Name220 rrrrbankpay.BankInfo = req.BankInfo221 rrrrbankpay.BankName = req.BankName222 ret.SetDataSection("bank_pay", rrrrbankpay)223 ret.SetErrCode(rsp.Code, GetErrorMessage(rsp.Code))224 }225 return226}227//////////// bank end ///////////////228func (this *CurrencyGroup) Alipay(c *gin.Context) {229 ret := NewPublciError()230 defer func() {231 c.JSON(http.StatusOK, ret.GetResult())232 }()233 req := struct {234 Uid uint64 `form:"uid" json:"uid" binding:"required"`235 Name string `form:"name" json:"name" binding:"required"`236 Alipay string `form:"alipay" json:"alipay" binding:"required"`237 Verify string `form:"verify" json:"verify" binding:"required"`238 ReceiptCode string `form:"receipt_code" json:"receipt_code" binding:"required"`239 }{}240 if err := c.ShouldBind(&req); err != nil {241 log.Errorf(err.Error())242 ret.SetErrCode(ERRCODE_PARAM, GetErrorMessage(ERRCODE_PARAM))243 return244 }245 url, err := this.upload_picture(req.ReceiptCode)246 if err != nil {247 log.Errorf(err.Error())248 ret.SetErrCode(ERRCODE_UOPLOA_FAILED, err.Error())249 return250 }251 if url == `` {252 log.Errorf(err.Error())253 ret.SetErrCode(ERRCODE_UOPLOA_FAILED, err.Error())254 return255 }256 rsp, err := rpc.InnerService.CurrencyService.CallAliPay(&proto.AlipayRequest{257 Uid: req.Uid,258 Name: req.Name,259 Alipay: req.Alipay,260 ReceiptCode: url,261 Verify: req.Verify,262 })263 if err != nil {264 log.Errorln(err.Error())265 ret.SetErrCode(ERRCODE_UNKNOWN, GetErrorMessage(ERRCODE_UNKNOWN))266 return267 } else {268 var alipay RspAliPay269 alipay.Uid = req.Uid270 alipay.Name = req.Name271 alipay.Alipay = req.Alipay272 alipay.Receipt_code = url273 ret.SetErrCode(rsp.Code, GetErrorMessage(rsp.Code))274 //fmt.Println(alipay)275 ret.SetDataSection("ali_pay", alipay)276 return277 }278}279func (this *CurrencyGroup) GetAliPay(c *gin.Context) {280 ret := NewPublciError()281 defer func() {282 c.JSON(http.StatusOK, ret.GetResult())283 }()284 req := struct {285 Uid uint64 `form:"uid" json:"uid" binding:"required"`286 }{}287 err := c.ShouldBind(&req)288 if err != nil {289 log.Errorf(err.Error())290 ret.SetErrCode(ERRCODE_PARAM, GetErrorMessage(ERRCODE_PARAM))291 return292 }293 rsp, err := rpc.InnerService.CurrencyService.CallGetAliPay(&proto.PayRequest{294 Uid: req.Uid,295 })296 var alipay RspAliPay297 err = json.Unmarshal([]byte(rsp.Data), &alipay)298 if err != nil {299 log.Errorln(err.Error())300 ret.SetErrCode(ERRCODE_UNKNOWN, GetErrorMessage(ERRCODE_UNKNOWN))301 return302 } else {303 ret.SetDataSection("ali_pay", alipay)304 ret.SetErrCode(rsp.Code, GetErrorMessage(rsp.Code))305 }306 return307}308func (this *CurrencyGroup) UpdateAliPay(c *gin.Context) {309 ret := NewPublciError()310 defer func() {311 c.JSON(http.StatusOK, ret.GetResult())312 }()313 req := struct {314 Uid uint64 `form:"uid" json:"uid" binding:"required"`315 Name string `form:"name" json:"name" binding:"required"`316 Alipay string `form:"alipay" json:"alipay" binding:"required"`317 Verify string `form:"verify" json:"verify" binding:"required"`318 ReceiptCode string `form:"receipt_code" json:"receipt_code" binding:"required"`319 }{}320 if err := c.ShouldBind(&req); err != nil {321 log.Errorf(err.Error())322 ret.SetErrCode(ERRCODE_PARAM, GetErrorMessage(ERRCODE_PARAM))323 return324 }325 url, err := this.upload_picture(req.ReceiptCode)326 if err != nil {327 log.Errorf(err.Error())328 ret.SetErrCode(ERRCODE_UOPLOA_FAILED, err.Error())329 return330 }331 if url == `` {332 log.Errorf(err.Error())333 ret.SetErrCode(ERRCODE_UOPLOA_FAILED, err.Error())334 return335 }336 rsp, err := rpc.InnerService.CurrencyService.CallUpdateAliPay(&proto.AlipayRequest{337 Uid: req.Uid,338 //Token: req.Token,339 Name: req.Name,340 Alipay: req.Alipay,341 ReceiptCode: url,342 Verify: req.Verify,343 })344 if err != nil {345 log.Errorln(err.Error())346 ret.SetErrCode(ERRCODE_UNKNOWN, GetErrorMessage(ERRCODE_UNKNOWN))347 return348 } else {349 var alipay RspAliPay350 alipay.Uid = req.Uid351 alipay.Name = req.Name352 alipay.Alipay = req.Alipay353 alipay.Receipt_code = url354 ret.SetErrCode(rsp.Code, GetErrorMessage(rsp.Code))355 //fmt.Println(alipay)356 ret.SetDataSection("ali_pay", alipay)357 return358 }359}360///////////////////// ali pay end /////////////////////361func (py *CurrencyGroup) Paypal(c *gin.Context) {362 ret := NewPublciError()363 defer func() {364 c.JSON(http.StatusOK, ret.GetResult())365 }()366 var req PaypalPay367 err := c.ShouldBind(&req)368 if err != nil {369 log.Errorf(err.Error())370 ret.SetErrCode(ERRCODE_PARAM, GetErrorMessage(ERRCODE_PARAM))371 return372 }373 rsp, err := rpc.InnerService.CurrencyService.CallPaypal(&proto.PaypalRequest{374 Uid: req.Uid,375 //Token: req.Token,376 Paypal: req.Paypal,377 Verify: req.Verify,378 })379 if err != nil {380 log.Errorf(err.Error())381 ret.SetErrCode(ERRCODE_UNKNOWN, GetErrorMessage(ERRCODE_UNKNOWN))382 return383 }384 var paypay RspPaypalPay385 paypay.Paypal = req.Paypal386 paypay.Uid = req.Uid387 ret.SetDataSection("paypal_pay", paypay)388 ret.SetErrCode(rsp.Code)389 return390}391func (this *CurrencyGroup) GetPaypal(c *gin.Context) {392 ret := NewPublciError()393 defer func() {394 c.JSON(http.StatusOK, ret.GetResult())395 }()396 req := struct {397 Uid uint64 `form:"uid" json:"uid" binding:"required"`398 }{}399 err := c.ShouldBind(&req)400 if err != nil {401 log.Errorf(err.Error())402 ret.SetErrCode(ERRCODE_PARAM, GetErrorMessage(ERRCODE_PARAM))403 return404 }405 rsp, err := rpc.InnerService.CurrencyService.CallGetPaypal(&proto.PayRequest{406 Uid: req.Uid,407 })408 var paypay RspPaypalPay409 err = json.Unmarshal([]byte(rsp.Data), &paypay)410 if err != nil {411 log.Errorln(err.Error())412 ret.SetErrCode(ERRCODE_UNKNOWN, GetErrorMessage(ERRCODE_UNKNOWN))413 } else {414 ret.SetDataSection("paypal_pay", paypay)415 ret.SetErrCode(rsp.Code, GetErrorMessage(rsp.Code))416 }417 return418}419func (this *CurrencyGroup) UpdatePaypal(c *gin.Context) {420 ret := NewPublciError()421 defer func() {422 c.JSON(http.StatusOK, ret.GetResult())423 }()424 var req PaypalPay425 err := c.ShouldBind(&req)426 if err != nil {427 log.Errorf(err.Error())428 ret.SetErrCode(ERRCODE_PARAM, GetErrorMessage(ERRCODE_PARAM))429 return430 }431 rsp, err := rpc.InnerService.CurrencyService.CallUpdatePaypal(&proto.PaypalRequest{432 Uid: req.Uid,433 //Token: req.Token,434 Paypal: req.Paypal,435 //Verify: req.Verify,436 })437 if err != nil {438 log.Errorln(err.Error())439 ret.SetErrCode(ERRCODE_UNKNOWN, GetErrorMessage(ERRCODE_UNKNOWN))440 } else {441 var paypay RspPaypalPay442 paypay.Uid = req.Uid443 paypay.Paypal = req.Paypal444 ret.SetErrCode(rsp.Code, GetErrorMessage(rsp.Code))445 ret.SetDataSection("paypal_pay", paypay)446 }447 return448}449//////////////////////// paypal end ////////////////////////////////////450func (this *CurrencyGroup) WeChatPay(c *gin.Context) {451 ret := NewPublciError()452 defer func() {453 c.JSON(http.StatusOK, ret.GetResult())454 }()455 req := struct {456 Uid uint64 `form:"uid" json:"uid" binding:"required"`457 Name string `form:"name" json:"name" binding:"required"`458 Wechat string `form:"wechat" json:"wechat" binding:"required"`459 Verify string `form:"verify" json:"verify" binding:"required"`460 ReceiptCode string `form:"receipt_code" json:"receipt_code" binding:"required"`461 }{}462 if err := c.ShouldBind(&req); err != nil {463 log.Errorf(err.Error())464 ret.SetErrCode(ERRCODE_PARAM, GetErrorMessage(ERRCODE_PARAM))465 return466 }467 url, err := this.upload_picture(req.ReceiptCode)468 if err != nil {469 log.Errorf(err.Error())470 ret.SetErrCode(ERRCODE_UOPLOA_FAILED, err.Error())471 return472 }473 if url == `` {474 ret.SetErrCode(ERRCODE_UOPLOA_FAILED, err.Error())475 return476 }477 rsp, err := rpc.InnerService.CurrencyService.CallWeChatPay(&proto.WeChatPayRequest{478 Uid: req.Uid,479 Name: req.Name,480 Wechat: req.Wechat,481 ReceiptCode: url,482 Verify: req.Verify,483 })484 if err != nil {485 log.Errorf(err.Error())486 ret.SetErrCode(ERRCODE_UNKNOWN, GetErrorMessage(ERRCODE_UNKNOWN))487 return488 }489 if rsp.Code == ERRCODE_SUCCESS {490 var wechatPay RspWeChatPay491 wechatPay.Receipt_code = url492 wechatPay.Name = req.Name493 wechatPay.Uid = req.Uid494 wechatPay.Wechat = req.Wechat495 ret.SetDataSection("wechat_pay", wechatPay)496 ret.SetErrCode(rsp.Code, GetErrorMessage(rsp.Code))497 } else {498 ret.SetErrCode(rsp.Code, GetErrorMessage(rsp.Code))499 }500 return501}502func (this *CurrencyGroup) GetWeChatPay(c *gin.Context) {503 ret := NewPublciError()504 defer func() {505 c.JSON(http.StatusOK, ret.GetResult())506 }()507 req := struct {508 Uid uint64 `form:"uid" json:"uid" binding:"required"`509 }{}510 err := c.ShouldBind(&req)511 if err != nil {512 log.Errorf(err.Error())513 ret.SetErrCode(ERRCODE_PARAM, GetErrorMessage(ERRCODE_PARAM))514 return515 }516 rsp, err := rpc.InnerService.CurrencyService.CallGetWeChatPay(&proto.PayRequest{517 Uid: req.Uid,518 })519 var wechatPay RspWeChatPay520 err = json.Unmarshal([]byte(rsp.Data), &wechatPay)521 if err != nil {522 log.Errorln(err.Error())523 ret.SetErrCode(ERRCODE_UNKNOWN, GetErrorMessage(ERRCODE_UNKNOWN))524 return525 } else {526 ret.SetDataSection("wechat_pay", wechatPay)527 ret.SetErrCode(rsp.Code, GetErrorMessage(rsp.Code))528 }529 return530}531func (this *CurrencyGroup) UpdateWeChatPay(c *gin.Context) {532 ret := NewPublciError()533 defer func() {534 c.JSON(http.StatusOK, ret.GetResult())535 }()536 req := struct {537 Uid uint64 `form:"uid" json:"uid" binding:"required"`538 Name string `form:"name" json:"name" binding:"required"`539 Wechat string `form:"wechat" json:"wechat" binding:"required"`540 Verify string `form:"verify" json:"verify" binding:"required"`541 ReceiptCode string `form:"receipt_code" json:"receipt_code" binding:"required"`542 }{}543 if err := c.ShouldBind(&req); err != nil {544 log.Errorf(err.Error())545 ret.SetErrCode(ERRCODE_PARAM, GetErrorMessage(ERRCODE_PARAM))546 return547 }548 url, err := this.upload_picture(req.ReceiptCode)549 if err != nil {550 log.Errorf(err.Error())551 ret.SetErrCode(ERRCODE_UOPLOA_FAILED, err.Error())552 return553 }554 if url == `` {555 ret.SetErrCode(ERRCODE_UOPLOA_FAILED, err.Error())556 return557 }558 rsp, err := rpc.InnerService.CurrencyService.CallUpdateWeChatPay(&proto.WeChatPayRequest{559 Uid: req.Uid,560 Name: req.Name,561 Wechat: req.Wechat,562 ReceiptCode: url,563 Verify: req.Verify,564 })565 if err != nil {566 log.Errorln(err.Error())567 ret.SetErrCode(ERRCODE_UNKNOWN, GetErrorMessage(ERRCODE_UNKNOWN))568 return569 }570 if rsp.Code == ERRCODE_SUCCESS {571 var wechatPay RspWeChatPay572 wechatPay.Receipt_code = url573 wechatPay.Name = req.Name574 wechatPay.Uid = req.Uid575 wechatPay.Wechat = req.Wechat576 ret.SetDataSection("wechat_pay", wechatPay)577 ret.SetErrCode(rsp.Code, GetErrorMessage(rsp.Code))578 } else {579 ret.SetErrCode(rsp.Code, GetErrorMessage(rsp.Code))580 }581 return582}583//上传Ali coud584func (a *CurrencyGroup) upload_picture(file string) (string, error) {585 var remoteurl string = "https://sdun.oss-cn-shenzhen.aliyuncs.com/"586 client, err := oss.New("http://oss-cn-shenzhen.aliyuncs.com", "LTAIcJgRedhxruPq", "d7p6tWRfy0B2QaRXk7q4mb5seLROtb")587 if err != nil {588 // HandleError(err)589 panic(err)590 }591 bucket, err := client.Bucket("sdun")592 if err != nil {593 return "", err...

Full Screen

Full Screen

datasource.go

Source:datasource.go Github

copy

Full Screen

...34func (tsl *TslDatasource) MetricQuery(ctx context.Context, tsdbReq *datasource.DatasourceRequest) (*datasource.DatasourceResponse, error) {35 jsonQueries, err := parseJSONQueries(tsdbReq)36 if err != nil {37 resultSet := make([]*datasource.QueryResult, 1)38 resultSet[0] = tsl.GetErrorMessage(err, "")39 return nil, nil40 }41 params := map[string]string{"TSL-Query-Range": tsdbReq.TimeRange.FromRaw + "," + tsdbReq.TimeRange.ToRaw, "TSL-Line-Start": "1"}42 resultSet := make([]*datasource.QueryResult, len(jsonQueries))43 for index, item := range jsonQueries {44 hide, err := item.Get("hide").Bool()45 if err != nil {46 hide = false47 }48 hideAttributes, err := item.Get("hideAttributes").Bool()49 if err != nil {50 hideAttributes = false51 }52 hideLabels, err := item.Get("hideLabels").Bool()53 if err != nil {54 hideAttributes = false55 }56 refID, err := item.Get("refId").String()57 if err != nil {58 resultSet := make([]*datasource.QueryResult, 1)59 resultSet[0] = tsl.GetErrorMessage(errors.New("Couldn't parse a Grafana RefId"), "")60 continue61 }62 if hide {63 resultSet[index] = &datasource.QueryResult{RefId: refID}64 continue65 }66 tslHeader, err := item.Get("tslHeader").String()67 if err != nil {68 resultSet[index] = tsl.GetErrorMessage(errors.New("Couldn't parse Grafana Request Headers setting Data-source and Grafana variables"), refID)69 continue70 }71 script, err := item.Get("tsl").String()72 if err != nil {73 resultSet[index] = tsl.GetErrorMessage(errors.New("Couldn't parse TSL script"), refID)74 continue75 }76 tslString := tslHeader + "\n" + script77 basicAuth, err := item.Get("auth").String()78 token := ""79 if err == nil {80 token = tsl.GetTokenFromAuth(basicAuth)81 }82 backendType, err := item.Get("tslBackend").String()83 if err != nil {84 resultSet[index] = tsl.GetErrorMessage(errors.New("Couldn't parse Grafana TSL backend type"), refID)85 continue86 }87 queryScript, err := proxy.GenerateNativeQueriesWithParams(backendType, tslString, token, true, params)88 if err != nil {89 resultSet[index] = tsl.GetErrorMessage(err, refID)90 continue91 }92 switch backendType {93 case "warp10":94 resultSet[index] = tsl.GetWarp10Result(tsdbReq.Datasource.Url, queryScript, refID, hide, hideAttributes, hideLabels)95 break96 case "prometheus":97 resultSet[index] = tsl.GetPromResult(tsdbReq.Datasource.Url, queryScript, refID, basicAuth, hide, hideAttributes, hideLabels)98 break99 default:100 resultSet[index] = tsl.GetErrorMessage(errors.New("Couldn't find Grafana TSL backend type"), refID)101 }102 }103 result := &datasource.DatasourceResponse{Results: resultSet}104 return result, nil105}106// GetPromResult execute TSL native Queries on a Prometheus backend107func (tsl *TslDatasource) GetPromResult(endpoint, promScript, refID, basicAuth string, hide, hideAttributes, hideLabels bool) *datasource.QueryResult {108 promQueries := strings.Split(promScript, "\n")109 seriesSet := make([]*datasource.TimeSeries, 0)110 for _, query := range promQueries {111 if query == "" {112 continue113 }114 res, err := tsl.execProm(endpoint, query, basicAuth)115 if err != nil {116 return tsl.GetErrorMessage(err, refID)117 }118 promResponse := &PrometheusResponse{}119 err = json.Unmarshal([]byte(res), promResponse)120 if err != nil {121 return tsl.GetErrorMessage(errors.New("Couldn't unmarshall prometheus response"), refID)122 }123 if promResponse.Status == "error" {124 return tsl.GetErrorMessage(errors.New(res), refID)125 }126 for _, series := range promResponse.Data.Result {127 metrics := series.Metric128 seriesName := metrics["__name__"]129 tags := make(map[string]string)130 if !hideLabels {131 delete(metrics, "__name__")132 delete(metrics, ".app")133 labels, err := json.Marshal(metrics)134 if err != nil {135 return tsl.GetErrorMessage(errors.New("Couldn't unmarshall time series labels"), refID)136 }137 tags["l"] = string(labels)138 }139 // Parse series data points140 seriesPoint := make([]*datasource.Point, len(series.Values))141 for dpIndex, dp := range series.Values {142 hasTimestamp := false143 timestamp := int64(-1)144 switch tick := dp[0].(type) {145 case float64:146 timestamp = int64(tick) * 1000147 hasTimestamp = true148 break149 case int64:150 timestamp = tick * 1000151 hasTimestamp = true152 break153 case int:154 timestamp = int64(tick) * 1000155 hasTimestamp = true156 break157 }158 hasValue := false159 value := float64(-1)160 switch val := dp[1].(type) {161 case float64:162 value = val163 hasValue = true164 break165 case string:166 value, err = strconv.ParseFloat(val, 64)167 if err != nil {168 hasValue = false169 break170 }171 hasValue = true172 break173 case int64:174 value = float64(val)175 hasValue = true176 break177 case int:178 value = float64(val)179 hasValue = true180 break181 }182 if hasTimestamp && hasValue {183 seriesPoint[dpIndex] = &datasource.Point{Timestamp: timestamp, Value: value}184 } else {185 // Break in case of error186 if !hasTimestamp {187 return tsl.GetErrorMessage(errors.New("Unvalid time series timestamp type"), refID)188 } else if !hasValue {189 return tsl.GetErrorMessage(errors.New("Unvalid time series value type"), refID)190 }191 }192 }193 series := &datasource.TimeSeries{Name: seriesName, Tags: tags, Points: seriesPoint}194 seriesSet = append(seriesSet, series)195 }196 }197 return &datasource.QueryResult{Series: seriesSet, RefId: refID}198}199// Execute PromQL on prometheus metrics backend200func (tsl *TslDatasource) execProm(endpoint, query, basicAuth string) (string, error) {201 u, err := url.Parse(endpoint + query)202 if err != nil {203 return "", err204 }205 httpReq, err := http.NewRequest("GET", u.String(), nil)206 httpReq.Header.Add("Authorization", basicAuth)207 if err != nil {208 return "", err209 }210 res, err := http.DefaultClient.Do(httpReq)211 if err != nil {212 return "", err213 }214 defer res.Body.Close()215 buf := new(bytes.Buffer)216 buf.ReadFrom(res.Body)217 if res.StatusCode != http.StatusOK {218 //return "",219 var message proxy.PromError220 json.Unmarshal(buf.Bytes(), &message)221 return buf.String(), errors.New("Fail to execute Prom request: " + message.Error)222 }223 return buf.String(), nil224}225// GetWarp10Result execute TSL native Queries on a Warp10 backend226func (tsl *TslDatasource) GetWarp10Result(endpoint, warpScript, refID string, hide, hideAttributes, hideLabels bool) *datasource.QueryResult {227 warpServer := NewWarpServer(endpoint, "warp10")228 resp, err := warpServer.QueryGTSs(warpScript)229 if err != nil {230 return tsl.GetErrorMessage(err, refID)231 }232 gtsSet := resp[0]233 seriesSet := make([]*datasource.TimeSeries, len(gtsSet))234 for i, gts := range gtsSet {235 // Parse series tags236 tags := make(map[string]string)237 if !hideLabels {238 labels, err := json.Marshal(gts.Labels)239 if err != nil {240 return tsl.GetErrorMessage(errors.New("Couldn't unmarshall time series labels"), refID)241 }242 tags["l"] = string(labels)243 }244 if !hideAttributes {245 attributes, err := json.Marshal(gts.Attrs)246 if err != nil {247 return tsl.GetErrorMessage(errors.New("Couldn't unmarshall time series attributes"), refID)248 }249 tags["a"] = string(attributes)250 }251 // Parse series data points252 seriesPoint := make([]*datasource.Point, len(gts.Values))253 for dpIndex, dp := range gts.Values {254 hasTimestamp := false255 timestamp := int64(-1)256 switch tick := dp[0].(type) {257 case float64:258 timestamp = int64(tick) / 1000259 hasTimestamp = true260 break261 case int64:262 timestamp = tick / 1000263 hasTimestamp = true264 break265 case int:266 timestamp = int64(tick) / 1000267 hasTimestamp = true268 break269 }270 hasValue := false271 value := float64(-1)272 switch val := dp[len(dp)-1].(type) {273 case float64:274 value = val275 hasValue = true276 break277 case int64:278 value = float64(val)279 hasValue = true280 break281 case int:282 value = float64(val)283 hasValue = true284 break285 }286 if hasTimestamp && hasValue {287 seriesPoint[dpIndex] = &datasource.Point{Timestamp: timestamp, Value: value}288 } else {289 // Break in case of error290 if !hasTimestamp {291 return tsl.GetErrorMessage(errors.New("Unvalid time series timestamp type"), refID)292 } else if !hasValue {293 return tsl.GetErrorMessage(errors.New("Unvalid time series value type"), refID)294 }295 }296 }297 // Return series298 series := &datasource.TimeSeries{Name: gts.Class, Tags: tags, Points: seriesPoint}299 seriesSet[i] = series300 }301 return &datasource.QueryResult{Series: seriesSet, RefId: refID}302}303// GetErrorMessage generate a Query Result error message based on a golang error304func (tsl *TslDatasource) GetErrorMessage(err error, refID string) *datasource.QueryResult {305 if refID != "" {306 return &datasource.QueryResult{Error: err.Error(), RefId: refID}307 }308 return &datasource.QueryResult{Error: err.Error()}309}310// GetTokenFromAuth is fetching the token from the request basic auth311func (tsl *TslDatasource) GetTokenFromAuth(basicAuth string) string {312 // Getting token from BasicAuth313 s := strings.SplitN(basicAuth, " ", 2)314 if len(s) != 2 {315 return ""316 }317 b, err := base64.StdEncoding.DecodeString(s[1])318 if err != nil {...

Full Screen

Full Screen

config.go

Source:config.go Github

copy

Full Screen

...27 PutType int32 `json:"put_type"`28 }{}29 if err := c.ShouldBind(&req); err != nil {30 log.Errorln(err.Error())31 ret.SetErrCode(ERRCODE_PARAM, GetErrorMessage(ERRCODE_PARAM))32 return33 }34 err = model.PutToConsul(req.PutType)35 if err != nil {36 ret.SetErrCode(ERRCODE_UNKNOWN, GetErrorMessage(ERRCODE_UNKNOWN))37 return38 }39 ret.SetErrCode(ERRCODE_SUCCESS, GetErrorMessage(ERRCODE_SUCCESS))40 return41}42func (this *ConfigGroup) ConfigList(c *gin.Context) {43 ret := NewPublciError()44 defer func() {45 c.JSON(http.StatusOK, ret.GetResult())46 }()47 req := struct {48 PutType int32 `form:"put_type" json:"put_type" binding:"required"`49 }{}50 if err := c.ShouldBindQuery(&req); err != nil {51 log.Errorln(err.Error())52 ret.SetErrCode(ERRCODE_PARAM, GetErrorMessage(ERRCODE_PARAM))53 return54 }55 result, err := model.GetFromConsul(req.PutType)56 if err != nil {57 ret.SetErrCode(ERRCODE_UNKNOWN, GetErrorMessage(ERRCODE_UNKNOWN))58 return59 }60 ret.SetDataSection("list", result)61 //ret.SetDataValue(result)62 ret.SetErrCode(ERRCODE_SUCCESS, GetErrorMessage(ERRCODE_SUCCESS))63 return64}65//66//func (this *ConfigGroup) ConfigDelete(c *gin.Context){67// ret := NewPublciError()68// defer func(){69// c.JSON(http.StatusOK, ret.GetResult())70// }()71// consulClient := dao.DB.GetConsulCli()72// fmt.Println(consulClient)73//74// kv := consulClient.KV()75// dw, err := kv.Delete("k", nil)76// if err != nil {77// fmt.Println(err)78// }79// fmt.Println(dw)80//81// ret.SetErrCode(ERRCODE_SUCCESS, GetErrorMessage(ERRCODE_SUCCESS))82// return83//}84//85//func (this *ConfigGroup) ConfigPutOne(c *gin.Context) {86// ret := NewPublciError()87// defer func() {88// c.JSON(http.StatusOK, ret.GetResult())89// }()90//91// mconfig := new(model.ConfigQuenesModel)92// mconfig.GetAllQuenes()93//94// consulClient := dao.DB.GetConsulCli()95// fmt.Println(consulClient)96//97// kv := consulClient.KV()98// p := &api.KVPair{Key: "k", Value: []byte("vvvvvvvvv")}99// wm, err := kv.Put(p, nil)100// if err != nil {101// fmt.Println(err)102// }103// fmt.Println(wm)104//105// p = &api.KVPair{Key: "ads", Value: []byte("vvvvvvvasdfffffffffffffljlkfdjlaksjflkasjdflkkkkkkkkkkkkkkkkkkkkkkkkkkkkkksvv")}106// wm, err = kv.Put(p, nil)107// if err != nil {108// fmt.Println(err)109// }110// fmt.Println(wm)111//112// ret.SetErrCode(ERRCODE_SUCCESS, GetErrorMessage(ERRCODE_SUCCESS))113// return114//}...

Full Screen

Full Screen

GetErrorMessage

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 if err != nil {4 fmt.Println(err)5 }6 defer driver.Close()7 session, err := driver.Session(neo4j.AccessModeWrite)8 if err != nil {9 fmt.Println(err)10 }11 defer session.Close()12 result, err := session.Run("CREATE (a:Person {name: $name}) RETURN a.name + ', from node ' + id(a)", map[string]interface{}{"name": "Arthur"})13 if err != nil {14 fmt.Println(err)15 }16 for result.Next() {17 fmt.Println(result.Record().GetByIndex(0))18 }19 if err := result.Err(); err != nil {20 fmt.Println(err)21 }22}23import (24func main() {25 if err != nil {26 fmt.Println(err)27 }28 defer driver.Close()29 session, err := driver.Session(neo4j.AccessModeWrite)30 if err != nil {31 fmt.Println(err)32 }33 defer session.Close()34 result, err := session.Run("CREATE (a:Person {name: $name}) RETURN a.name + ', from node ' + id(a)", map[string]interface{}{"name": "Arthur"})35 if err != nil {36 fmt.Println(err)37 }38 for result.Next() {39 fmt.Println(result.Record().GetByIndex(0))40 }41 if err := result.Err(); err != nil {42 fmt.Println(err)43 }44}45import (

Full Screen

Full Screen

GetErrorMessage

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 db := mysql.New("tcp", "", "localhost:3306", "root", "root", "test")4 err := db.Connect()5 if err != nil {6 fmt.Println("Error connecting to database: ", err)7 }8 defer db.Close()9 res, err := db.Start("select * from test")10 if err != nil {11 fmt.Println("Error executing query: ", err)12 }13 defer res.End()14 for {15 row, err := res.GetRow()16 if err != nil {17 if err == mysql.ErrNoRows {18 }19 fmt.Println("Error getting row: ", err)20 }21 fmt.Println(row)22 }23}24import (25func main() {26 db := mysql.New("tcp", "", "localhost:3306", "root", "root", "test")27 err := db.Connect()28 if err != nil {29 fmt.Println("Error connecting to database: ", err)30 }31 defer db.Close()32 res, err := db.Start("select * from test")33 if err != nil {34 fmt.Println("Error executing query: ", err)35 }36 defer res.End()37 for {38 row, err := res.GetRow()39 if err != nil {40 if err == mysql.ErrNoRows {41 }42 fmt.Println("Error getting row:

Full Screen

Full Screen

GetErrorMessage

Using AI Code Generation

copy

Full Screen

1import "fmt"2type Result struct {3}4func (r Result) GetErrorMessage() string {5}6func main() {7 r := Result{Id: 101, Message: "Record Not Found"}8 fmt.Println(r.GetErrorMessage())9}10import "fmt"11type Result struct {12}13func (r Result) GetErrorMessage() string {14}15func main() {16 r := &Result{Id: 101, Message: "Record Not Found"}17 fmt.Println(r.GetErrorMessage())18}19In the above program, we have created a method named GetErrorMessage() which takes no arguments and returns a string. This method

Full Screen

Full Screen

GetErrorMessage

Using AI Code Generation

copy

Full Screen

1import (2type Result struct {3}4func (r *Result) GetErrorMessage() string {5}6func main() {7 fmt.Println("Go: Error message is: ", result.GetErrorMessage())8}9{10 char* errorMessage;11};12char* GetErrorMessage(struct Result* result);13char* GetErrorMessage(struct Result* result)14{15 return result->errorMessage;16}17import "C"18import (19func main() {20 result.errorMessage = C.CString("Error message from C")21 fmt.Println("Go: Error message is: ", C.GoString(C.GetErrorMessage(&result)))22}

Full Screen

Full Screen

GetErrorMessage

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 r := result.NewResult()4 r.SetStatus(1)5 r.SetMessage("Error occured")6 fmt.Println(r.GetErrorMessage())7}

Full Screen

Full Screen

GetErrorMessage

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(res.GetErrorMessage())4}5import (6func main() {7 fmt.Println(res.GetErrorMessage())8}9import (10func main() {11 fmt.Println(res.GetErrorMessage())12}13import (14func main() {15 fmt.Println(res.GetErrorMessage())16}17import (18func main() {19 fmt.Println(res.GetErrorMessage())20}21import (22func main() {23 fmt.Println(res.GetErrorMessage())24}25import (26func main() {27 fmt.Println(res.GetErrorMessage())28}29import (30func main() {31 fmt.Println(res.GetErrorMessage())32}33import (34func main() {

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful