How to use Info method of ui Package

Best Testkube code snippet using ui.Info

spy.go

Source:spy.go Github

copy

Full Screen

...22 var (23 factor *model.Factor24 mid = eventMsg.ActiveMid25 )26 ui, err := s.UserInfo(c, mid, ip.InternalIP())27 if err != nil {28 log.Error("s.UserInfo(%d) err(%v)", mid, err)29 return30 }31 // if blocked already , return32 // if ui.State == model.StateBlock {33 // return34 // }35 // get factor by servieName , eventName , riskLevel36 if factor, err = s.factor(c, eventMsg.Service, eventMsg.Event, eventMsg.RiskLevel); err != nil {37 log.Error("s.factor(%s, %s, %d) error(%v)", eventMsg.Service, eventMsg.Event, eventMsg.RiskLevel, err)38 return39 }40 s.promEventScore.Incr("change")41 // mark eventScore decrease42 if factor.FactorVal < 1.0 {43 s.promEventScore.Incr("decrease")44 }45 // calc all score46 ui.EventScore = s.calcFactorScore(ui.EventScore, factor)47 ui.Score = s.calcScore(ui.BaseScore, ui.EventScore)48 if err = s.updateEventInfo(c, ui, factor, eventMsg); err != nil {49 log.Error("s.updateEventInfo(%v, %v, %v) error(%v)", ui, factor, eventMsg, err)50 return51 }52 s.updateInfoCache(c, ui)53 // check punishment.54 _, err = s.BlockFilter(c, ui)55 if err != nil {56 log.Error("s.BlockFilter(%v) error(%v)", ui, err)57 return58 }59 return60}61func (s *Service) updateEventInfo(c context.Context, ui *model.UserInfo, factor *model.Factor, eventMsg *model.EventMessage) (err error) {62 var (63 tx *sql.Tx64 )65 if tx, err = s.dao.BeginTran(c); err != nil {66 log.Error("s.dao.BeginTran() err(%v)", err)67 return68 }69 defer func() {70 if err != nil {71 if err1 := tx.Rollback(); err1 != nil {72 log.Error("tx.Rollback() error(%v)", err1)73 }74 return75 }76 if err = tx.Commit(); err != nil {77 log.Error("tx.Commit() error(%v)", err)78 }79 }()80 // update info.81 if err = s.dao.TxUpdateInfo(c, tx, ui); err != nil {82 log.Error("s.dao.UpsertInfo(%v) error(%v)", ui, err)83 return84 }85 if err = s.txAddHistory(c, tx, ui, factor, eventMsg); err != nil {86 log.Error("s.addHistory(%v, %v, %v) error(%v)", ui, factor, eventMsg, err)87 return88 }89 s.dao.PubScoreChange(c, ui.Mid, &model.ScoreChange{90 Mid: ui.Mid,91 Score: ui.Score,92 TS: time.Now().Unix(),93 Reason: eventMsg.Service,94 RiskLevel: eventMsg.RiskLevel,95 })96 return97}98// factor get facory by serviceName , eventName , riskLevel.99func (s *Service) factor(c context.Context, serviceName, eventName string, riskLevel int8) (factor *model.Factor, err error) {100 var (101 event *model.Event102 )103 if event, err = s.dao.Event(c, eventName); err != nil {104 log.Error("s.dao.Event(%s) error(%v)", eventName, err)105 return106 }107 if event == nil {108 log.Error("event(%s) not support", eventName)109 err = ecode.SpyEventNotExist110 return111 }112 if factor, err = s.dao.Factor(c, event.ServiceID, event.ID, riskLevel); err != nil {113 log.Error("s.dao.Factor(%d, %d, %d) error(%v)", event.ServiceID, event.ID, riskLevel, err)114 return115 }116 if factor == nil {117 log.Warn("factor(service=%d,event=%d,risklevel=%d) not support", event.ServiceID, event.ID, riskLevel)118 err = ecode.SpyFactorNotExist119 return120 }121 return122}123// UserInfo get UserInfo by mid , from cache or db or generate.124func (s *Service) UserInfo(c context.Context, mid int64, ip string) (ui *model.UserInfo, err error) {125 ui, err = s.userInfo(c, mid)126 if ui != nil {127 return128 }129 // user info not generated , so let's do it.130 if ui, err = s.initUserInfo(c, mid, ip); err != nil {131 log.Error("s.generateUserInfo(%d) error(%v)", mid, err)132 return133 }134 return135}136// UserInfoAsyn get UserInfo by mid , from cache or db or asyn generate.137func (s *Service) UserInfoAsyn(c context.Context, mid int64) (ui *model.UserInfo, err error) {138 ui, err = s.userInfo(c, mid)139 if ui != nil {140 return141 }142 ip := metadata.String(c, metadata.RemoteIP)143 s.infomission(func() {144 if _, err1 := s.initUserInfo(context.TODO(), mid, ip); err1 != nil {145 log.Error("s.generateUserInfo(%d) error(%v)", mid, err1)146 return147 }148 })149 return150}151// UserInfo get UserInfo by mid , from cache or db.152func (s *Service) userInfo(c context.Context, mid int64) (ui *model.UserInfo, err error) {153 var cacheFlag = true154 // get info from cache.155 if ui, err = s.dao.UserInfoCache(c, mid); err != nil {156 cacheFlag = false157 err = nil158 log.Error("s.dao.InfoCache(%d) error(%v)", mid, err)159 }160 // return if cache exist.161 if ui != nil {162 return163 }164 // get info from db.165 if ui, err = s.dao.UserInfo(c, mid); err != nil {166 log.Error("s.dao.Info(%d) error(%v)", mid, err)167 return168 }169 if ui != nil {170 // reload to cache171 if cacheFlag {172 s.updateInfoCache(c, ui)173 }174 }175 return176}177// Info returns user info.178func (s *Service) Info(c context.Context, mid int64) (ui *model.UserInfo, err error){179 ui, err = s.UserInfoAsyn(c, mid)180 if err != nil {181 return182 }183 if ui == nil {184 // asyn init user score , return def score.185 ui = &model.UserInfo{Mid: mid, Score: model.SpyInitScore}186 }187 return ui, nil188}189// initUserInfo .190func (s *Service) initUserInfo(c context.Context, mid int64, ip string) (ui *model.UserInfo, err error) {191 var (192 tx *sql.Tx193 // init default info194 fakeFactor = &model.Factor{195 NickName: "initialization",196 ServiceID: -1,197 EventID: conf.Conf.Property.Event.InitEventID,198 GroupID: -1,199 RiskLevel: 1,200 FactorVal: 1.0,201 }202 fakeEventMsg = &model.EventMessage{203 IP: "127.0.0.1",204 ActiveMid: mid,205 TargetMid: mid,206 Effect: "initialization",207 RiskLevel: 1,208 }209 )210 // start generate logic.211 ui = &model.UserInfo{212 Mid: mid,213 EventScore: conf.Conf.Property.Score.EventInit,214 State: model.StateNormal,215 }216 if ui.BaseScore, err = s.getBaseScore(c, mid, ip); err != nil {217 log.Error("s.calcBaseScore(%d, %s) error(%v)", mid, ip, err)218 return219 }220 ui.Score = s.calcScore(ui.BaseScore, ui.EventScore)221 // add new info into db.222 if tx, err = s.dao.BeginTran(c); err != nil {223 log.Error("s.dao.BeginTran() err(%v)", err)224 return225 }226 defer func() {227 if err != nil {228 if err1 := tx.Rollback(); err1 != nil {229 log.Error("tx.Rollback() error(%v)", err1)230 }231 return232 }233 if err = tx.Commit(); err != nil {234 log.Error("tx.Commit() error(%v)", err)235 }236 }()237 if ui.ID, err = s.dao.TxAddInfo(c, tx, ui); err != nil {238 log.Error("s.userDao.NewInfo(%d, %v) error(%v)", mid, ui, err)239 return240 }241 if err = s.txAddHistory(c, tx, ui, fakeFactor, fakeEventMsg); err != nil {242 log.Error("s.addHistory(%v, %v, %v) error(%v)", ui, fakeFactor, fakeEventMsg, err)243 return244 }245 s.updateInfoCache(c, ui)246 s.dao.PubScoreChange(c, mid, &model.ScoreChange{247 Mid: mid,248 Score: ui.Score,249 TS: time.Now().Unix(),250 })251 return252}253func (s *Service) calcFactorScore(preScore int8, factor *model.Factor) (score int8) {254 return int8(float64(preScore) * factor.FactorVal)255}256// calc real score.257func (s *Service) calcScore(baseScore, eventScore int8) (score int8) {258 return int8(float64(baseScore) * float64(eventScore) / float64(_score))259}260// getBaseScore get base score.261func (s *Service) getBaseScore(c context.Context, mid int64, ip string) (score int8, err error) {262 var (263 judgementInfo *JudgementInfo264 factorMeta FactoryMeta265 factor *model.Factor266 )267 if judgementInfo, err = s.getJudgementInfo(c, mid, ip); err != nil {268 return269 }270 if factorMeta, err = s.getBaseScoreFactor(judgementInfo); err != nil {271 return272 }273 log.Info("getBaseScoreFactor mid(%d) meta(%v)", mid, factorMeta)274 if factor, err = s.factor(c, factorMeta.serviceName, factorMeta.eventName, factorMeta.riskLevel); err != nil {275 log.Error("s.factor(%s, %s) error(%v)", conf.Conf.Property.Event.ServiceName, conf.Conf.Property.Event.BindMailOnly, 1)276 return277 }278 score = s.calcFactorScore(conf.Conf.Property.Score.BaseInit, factor)279 return280}281// ReBuildPortrait reBuild user info.282func (s *Service) ReBuildPortrait(c context.Context, mid int64, reason string) (err error) {283 var (284 tx *sql.Tx285 )286 ui, err := s.UserInfo(c, mid, ip.InternalIP())287 if err != nil || ui == nil {288 log.Error("user portrait not fund, mid(%d, %v), err(%v)", mid, ui, err)289 return290 }291 s.promEventScore.Incr("change")292 s.resetScore(c, ui, ui.BaseScore, _score)293 if tx, err = s.dao.BeginTran(c); err != nil {294 log.Error("s.dao.BeginTran() err(%v)", err)295 return296 }297 defer func() {298 if err != nil {299 if err1 := tx.Rollback(); err1 != nil {300 log.Error("tx.Rollback() error(%v)", err1)301 }302 return303 }304 if err = tx.Commit(); err != nil {305 log.Error("tx.Commit() error(%v)", err)306 }307 }()308 if err = s.dao.TxUpdateEventScoreReLive(c, tx, ui.Mid, ui.EventScore, ui.Score); err != nil {309 log.Error("s.dao.TxUpdateEventScoreReLive(%d, %d, %d), err(%v)", ui.Mid, ui.EventScore, ui.Score, err)310 return311 }312 if err = s.txAddHistory(c, tx, ui, &model.Factor{}, &model.EventMessage{Effect: reason}); err != nil {313 log.Error("s.addHistory(%+v), err(%v)", ui, err)314 return315 }316 s.updateInfoCache(c, ui)317 s.dao.PubScoreChange(c, mid, &model.ScoreChange{318 Mid: mid,319 Score: ui.Score,320 TS: time.Now().Unix(),321 })322 return323}324// UpdateUserScore update user score325func (s *Service) UpdateUserScore(c context.Context, mid int64, ip, effect string) (err error) {326 var (327 tx *sql.Tx328 factor = &model.Factor{}329 eventMsg = &model.EventMessage{Effect: effect}330 preBaseScore int8331 )332 ui, err := s.UserInfo(c, mid, ip)333 if err != nil || ui == nil {334 log.Error("user portrait not found, mid(%d, %v), err(%v)", mid, ui, err)335 return336 }337 preBaseScore = ui.BaseScore338 if ui.BaseScore, err = s.getBaseScore(c, mid, ip); err != nil {339 log.Error("s.calcBaseScore(%d, %s) error(%v)", mid, ip, err)340 return341 }342 s.promBaseScore.Incr("change")343 if ui.BaseScore < preBaseScore {344 s.promBaseScore.Incr("decrease")345 }346 s.resetScore(c, ui, ui.BaseScore, ui.EventScore)347 if tx, err = s.dao.BeginTran(c); err != nil {348 log.Error("s.dao.BeginTran() err(%v)", err)349 return350 }351 defer func() {352 if err != nil {353 if err1 := tx.Rollback(); err1 != nil {354 log.Error("tx.Rollback() error(%v)", err1)355 }356 return357 }358 if err = tx.Commit(); err != nil {359 log.Error("tx.Commit() error(%v)", err)360 }361 }()362 if err = s.dao.TxUpdateBaseScore(c, tx, ui); err != nil {363 log.Error("s.dao.UpdateBaseScore(%v), err(%v)", ui, err)364 return365 }366 if err = s.txAddHistory(c, tx, ui, factor, eventMsg); err != nil {367 log.Error("s.addHistory(%v, %v, %v) error(%v)", ui, factor, eventMsg, err)368 return369 }370 s.updateInfoCache(c, ui)371 s.dao.PubScoreChange(c, mid, &model.ScoreChange{372 Mid: mid,373 Score: ui.Score,374 TS: time.Now().Unix(),375 })376 return377}378// RefreshBaseScore refresh base score.379func (s *Service) RefreshBaseScore(c context.Context, arg *spy.ArgReset) (err error) {380 var (381 tx *sql.Tx382 mid = arg.Mid383 ip = "ip"384 eventMsg = &model.EventMessage{Effect: "手动更新基础分值"}385 preBaseScore int8386 )387 ui, err := s.UserInfo(c, mid, "ip")388 if err != nil || ui == nil {389 log.Error("user portrait not found, mid(%d, %v), err(%v)", mid, ui, err)390 return391 }392 preBaseScore = ui.BaseScore393 if ui.BaseScore, err = s.getBaseScore(c, mid, ip); err != nil {394 log.Error("s.calcBaseScore(%d, %s) error(%v)", mid, ip, err)395 return396 }397 s.promBaseScore.Incr("change")398 if ui.BaseScore < preBaseScore {399 s.promBaseScore.Incr("decrease")400 }401 s.resetScore(c, ui, ui.BaseScore, ui.EventScore)402 if tx, err = s.dao.BeginTran(c); err != nil {403 log.Error("s.dao.BeginTran() err(%v)", err)404 return405 }406 defer func() {407 if err != nil {408 if err1 := tx.Rollback(); err1 != nil {409 log.Error("tx.Rollback() error(%v)", err1)410 }411 return412 }413 if err = tx.Commit(); err != nil {414 log.Error("tx.Commit() error(%v)", err)415 }416 }()417 if err = s.dao.TxUpdateBaseScore(c, tx, ui); err != nil {418 log.Error("s.dao.UpdateBaseScore(%v), err(%v)", ui, err)419 return420 }421 if err = s.txAddHistory(c, tx, ui, &model.Factor{}, eventMsg); err != nil {422 log.Error("s.addHistory(%v, %v) error(%v)", ui, eventMsg, err)423 return424 }425 s.updateInfoCache(c, ui)426 s.dao.PubScoreChange(c, mid, &model.ScoreChange{427 Mid: mid,428 Score: ui.Score,429 TS: time.Now().Unix(),430 })431 return432}433//UpdateBaseScore update base score.434func (s *Service) UpdateBaseScore(c context.Context, arg *spy.ArgReset) (err error) {435 var (436 tx *sql.Tx437 event *model.Event438 eventMsg = &model.EventMessage{}439 )440 ui, err := s.UserInfo(c, arg.Mid, "ip")441 if err != nil || ui == nil {442 log.Error("user portrait not fund, mid(%d, %v), err(%v)", arg.Mid, ui, err)443 return444 }445 s.resetScore(c, ui, _score, ui.EventScore)446 eventMsg.Effect = fmt.Sprintf("人工恢复基础得分(%s)", arg.Operator)447 if tx, err = s.dao.BeginTran(c); err != nil {448 log.Error("s.dao.BeginTran() err(%v)", err)449 return450 }451 defer func() {452 if err != nil {453 if err1 := tx.Rollback(); err1 != nil {454 log.Error("tx.Rollback() error(%v)", err1)455 }456 return457 }458 if err = tx.Commit(); err != nil {459 log.Error("tx.Commit() error(%v)", err)460 }461 }()462 if err = s.dao.TxUpdateBaseScore(c, tx, ui); err != nil {463 log.Error("s.dao.UpdateBaseScore(%v), err(%v)", ui, err)464 return465 }466 if event, err = s.dao.Event(c, RestoreBaseScoreEvent); err != nil {467 log.Error("s.dao.Event(%s), err(%v)", RestoreBaseScoreEvent, err)468 return469 }470 if err = s.txAddHistory(c, tx, ui, &model.Factor{EventID: event.ID}, eventMsg); err != nil {471 log.Error("s.addHistory(%v), err(%v)", ui, err)472 return473 }474 s.dao.DelInfoCache(c, arg.Mid)475 s.dao.PubScoreChange(c, arg.Mid, &model.ScoreChange{476 Mid: arg.Mid,477 Score: ui.Score,478 TS: time.Now().Unix(),479 })480 return481}482//UpdateEventScore update event score.483func (s *Service) UpdateEventScore(c context.Context, arg *spy.ArgReset) (err error) {484 var (485 tx *sql.Tx486 eventMsg = &model.EventMessage{}487 )488 ui, err := s.UserInfo(c, arg.Mid, "ip")489 if err != nil || ui == nil {490 log.Error("user portrait not fund, mid(%d, %v), err(%v)", arg.Mid, ui, err)491 return492 }493 s.resetScore(c, ui, ui.BaseScore, _score)494 eventMsg.Effect = fmt.Sprintf("人工恢复行为得分(%s)", arg.Operator)495 if tx, err = s.dao.BeginTran(c); err != nil {496 log.Error("s.dao.BeginTran() err(%v)", err)497 return498 }499 defer func() {500 if err != nil {501 if err1 := tx.Rollback(); err1 != nil {502 log.Error("tx.Rollback() error(%v)", err1)503 }504 return505 }506 if err = tx.Commit(); err != nil {507 log.Error("tx.Commit() error(%v)", err)508 }509 }()510 if err = s.dao.TxUpdateEventScore(c, tx, ui.Mid, ui.EventScore, ui.Score); err != nil {511 log.Error("s.dao.UpdateEventScore(%v), err(%v)", ui, err)512 return513 }514 if err = s.txAddHistory(c, tx, ui, &model.Factor{}, eventMsg); err != nil {515 log.Error("s.addHistory(%v), err(%v)", ui, err)516 return517 }518 s.dao.DelInfoCache(c, arg.Mid)519 s.dao.PubScoreChange(c, arg.Mid, &model.ScoreChange{520 Mid: arg.Mid,521 Score: ui.Score,522 TS: time.Now().Unix(),523 })524 return525}526func (s *Service) txAddHistory(c context.Context, tx *sql.Tx, ui *model.UserInfo, factor *model.Factor, eventMsg *model.EventMessage) (err error) {527 // append event history528 var (529 ueh = &model.UserEventHistory{530 Mid: ui.Mid,531 EventID: factor.EventID,532 Score: ui.Score,533 BaseScore: ui.BaseScore,534 EventScore: ui.EventScore,535 Reason: eventMsg.Effect,536 FactorVal: factor.FactorVal,537 }538 remarkBytes []byte539 )540 if remarkBytes, err = json.Marshal(eventMsg); err != nil {541 log.Error("json.Marshal(%v) error(%v)", eventMsg, err)542 ueh.Remark = "{}"543 } else {544 ueh.Remark = string(remarkBytes)545 }546 if err = s.dao.TxAddEventHistory(c, tx, ueh); err != nil {547 log.Error("s.dao.AddEventHistory(%v) error(%v)", ueh, err)548 return549 }550 return551}552func (s *Service) resetScore(c context.Context, ui *model.UserInfo, baseScore, eventScore int8) (err error) {553 ui.BaseScore = baseScore554 ui.EventScore = eventScore555 ui.Score = int8(int(ui.EventScore) * int(ui.BaseScore) / _score)556 return557}558func (s *Service) updateInfoCache(c context.Context, ui *model.UserInfo) (err error) {559 s.mission(func() {560 if err = s.dao.SetUserInfoCache(context.TODO(), ui); err != nil {561 log.Error("s.dao.SetInfoCache(%v) error(%v)", ui, err)562 }563 })564 return565}566//ClearReliveTimes clear times.567func (s *Service) ClearReliveTimes(c context.Context, arg *spy.ArgReset) (err error) {568 var (569 tx *sql.Tx570 eventMsg = &model.EventMessage{}571 )572 ui, err := s.UserInfo(c, arg.Mid, "ip")573 if err != nil || ui == nil {574 log.Error("user portrait not fund, mid(%d, %v), err(%v)", arg.Mid, ui, err)575 return576 }577 ui.ReliveTimes = 0578 eventMsg.Effect = fmt.Sprintf("清除封号记次(%s)", arg.Operator)579 if tx, err = s.dao.BeginTran(c); err != nil {580 log.Error("s.dao.BeginTran() err(%v)", err)581 return582 }583 defer func() {584 if err != nil {585 if err1 := tx.Rollback(); err1 != nil {586 log.Error("tx.Rollback() error(%v)", err1)587 }588 return589 }590 if err = tx.Commit(); err != nil {591 log.Error("tx.Commit() error(%v)", err)592 }593 }()594 if err = s.dao.TxClearReliveTimes(c, tx, ui); err != nil {595 log.Error("s.dao.ClearReliveTimes(%v), err(%v)", ui, err)596 return597 }598 if err = s.txAddHistory(c, tx, ui, &model.Factor{}, eventMsg); err != nil {599 log.Error("s.addHistory(%v), err(%v)", ui, err)600 return601 }602 s.dao.DelInfoCache(c, arg.Mid)603 return604}605// TelRiskLevel tel risk level.606func (s *Service) TelRiskLevel(c context.Context, mid int64, ip string) (riskLevel int8, err error) {607 var (608 tel *model.TelInfo609 level int8610 )611 riskLevel = dao.TelRiskLevelUnknown612 if tel, err = s.dao.TelInfo(c, mid); err != nil {613 log.Error("s.dao.TelInfo error(%v)", err)614 return615 }616 if len(tel.Tel) == 0 {617 log.Warn("mid(%d) no tel info", mid)618 return619 }620 // white tel621 if telnum, theErr := strconv.ParseInt(tel.Tel, 10, 64); theErr == nil {622 for _, whiteTel := range s.c.Property.White.Tels {623 if telnum >= whiteTel.From && telnum <= whiteTel.To {624 log.Info("spy hit tel white from [%d] to [%d]", whiteTel.From, whiteTel.To)625 riskLevel = dao.TelRiskLevelLow626 return627 }628 }629 } else {630 log.Error("+v", errors.WithStack(theErr))631 }632 args := url.Values{}633 args.Set("accountType", fmt.Sprintf("%d", model.AccountType))634 args.Set("uid", fmt.Sprintf("%d", mid))635 args.Set("phoneNumber", tel.Tel)636 args.Set("registerTime", fmt.Sprintf("%d", tel.JoinTime))637 args.Set("registerIp", tel.JoinIP)638 if level, err = s.dao.RegisterProtection(c, args, ip); err != nil {...

Full Screen

Full Screen

stdioui.go

Source:stdioui.go Github

copy

Full Screen

...37// dispatch sends a request over the stdio38func (ui *StdIOUI) dispatch(serviceMethod string, args interface{}, reply interface{}) error {39 err := ui.client.Call(&reply, serviceMethod, args)40 if err != nil {41 log.Info("Error", "exc", err.Error())42 }43 return err44}45// notify sends a request over the stdio, and does not listen for a response46func (ui *StdIOUI) notify(serviceMethod string, args interface{}) error {47 ctx := context.Background()48 err := ui.client.Notify(ctx, serviceMethod, args)49 if err != nil {50 log.Info("Error", "exc", err.Error())51 }52 return err53}54func (ui *StdIOUI) ApproveTx(request *SignTxRequest) (SignTxResponse, error) {55 var result SignTxResponse56 err := ui.dispatch("ui_approveTx", request, &result)57 return result, err58}59func (ui *StdIOUI) ApproveSignData(request *SignDataRequest) (SignDataResponse, error) {60 var result SignDataResponse61 err := ui.dispatch("ui_approveSignData", request, &result)62 return result, err63}64func (ui *StdIOUI) ApproveListing(request *ListRequest) (ListResponse, error) {65 var result ListResponse66 err := ui.dispatch("ui_approveListing", request, &result)67 return result, err68}69func (ui *StdIOUI) ApproveNewAccount(request *NewAccountRequest) (NewAccountResponse, error) {70 var result NewAccountResponse71 err := ui.dispatch("ui_approveNewAccount", request, &result)72 return result, err73}74func (ui *StdIOUI) ShowError(message string) {75 err := ui.notify("ui_showError", &Message{message})76 if err != nil {77 log.Info("Error calling 'ui_showError'", "exc", err.Error(), "msg", message)78 }79}80func (ui *StdIOUI) ShowInfo(message string) {81 err := ui.notify("ui_showInfo", Message{message})82 if err != nil {83 log.Info("Error calling 'ui_showInfo'", "exc", err.Error(), "msg", message)84 }85}86func (ui *StdIOUI) OnApprovedTx(tx ethapi.SignTransactionResult) {87 err := ui.notify("ui_onApprovedTx", tx)88 if err != nil {89 log.Info("Error calling 'ui_onApprovedTx'", "exc", err.Error(), "tx", tx)90 }91}92func (ui *StdIOUI) OnSignerStartup(info StartupInfo) {93 err := ui.notify("ui_onSignerStartup", info)94 if err != nil {95 log.Info("Error calling 'ui_onSignerStartup'", "exc", err.Error(), "info", info)96 }97}98func (ui *StdIOUI) OnInputRequired(info UserInputRequest) (UserInputResponse, error) {99 var result UserInputResponse100 err := ui.dispatch("ui_onInputRequired", info, &result)101 if err != nil {102 log.Info("Error calling 'ui_onInputRequired'", "exc", err.Error(), "info", info)103 }104 return result, err105}...

Full Screen

Full Screen

user_info.go

Source:user_info.go Github

copy

Full Screen

...7 "go-common/library/log"8 "github.com/pkg/errors"9)10const (11 _getUserInfoByMid = "SELECT `id`, `mid`, `ver`, `vip_type`, `pay_type`, `pay_channel_id`, `status`, `overdue_time`, `recent_pay_time`, `ctime`, `mtime` FROM `tv_user_info` WHERE `mid`=?"12 _insertUserInfo = "INSERT INTO tv_user_info (`mid`, `ver`, `vip_type`, `pay_type`, `pay_channel_id`, `status`, `overdue_time`, `recent_pay_time`) VALUES (?,?,?,?,?,?,?,?)"13 _updateUserInfo = "UPDATE tv_user_info SET `status` = ?, `vip_type` = ?, `overdue_time`=?, `recent_pay_time`=?, `ver` = `ver` + 1 WHERE `mid` = ? AND `ver` = ?"14 _updateUserStatus = "UPDATE tv_user_info SET `status` = ?, `ver` = `ver` + 1 WHERE `mid` = ? AND `ver` = ?"15 _updateUserPayType = "UPDATE tv_user_info SET `pay_type` = ?, `ver` = `ver` + 1 WHERE `mid` = ? AND `ver` = ?"16)17// UserInfoByMid quires one row from tv_user_info.18func (d *Dao) RawUserInfoByMid(c context.Context, mid int64) (ui *model.UserInfo, err error) {19 row := d.db.QueryRow(c, _getUserInfoByMid, mid)20 ui = &model.UserInfo{}21 err = row.Scan(&ui.ID, &ui.Mid, &ui.Ver, &ui.VipType, &ui.PayType, &ui.PayChannelId, &ui.Status, &ui.OverdueTime, &ui.RecentPayTime, &ui.Ctime, &ui.Mtime)22 if err == sql.ErrNoRows {23 return nil, nil24 }25 if err != nil {26 log.Error("rows.Scan(%s) error(%v)", _getUserInfoByMid, err)27 err = errors.WithStack(err)28 return nil, err29 }30 return ui, nil31}32// TxInsertUserInfo insert one row into tv_user_info.33func (d *Dao) TxInsertUserInfo(ctx context.Context, tx *xsql.Tx, ui *model.UserInfo) (id int64, err error) {34 var (35 res sql.Result36 )37 if res, err = tx.Exec(_insertUserInfo, ui.Mid, ui.Ver, ui.VipType, ui.PayType, ui.PayChannelId, ui.Status, ui.OverdueTime, ui.RecentPayTime); err != nil {38 log.Error("tx.Exec(%s) error(%v)", _insertUserInfo, err)39 err = errors.WithStack(err)40 return41 }42 if id, err = res.LastInsertId(); err != nil {43 err = errors.WithStack(err)44 return45 }46 return47}48// TxUpdateUserInfo updates user info.49func (d *Dao) TxUpdateUserInfo(ctx context.Context, tx *xsql.Tx, ui *model.UserInfo) (err error) {50 if _, err = tx.Exec(_updateUserInfo, ui.Status, ui.VipType, ui.OverdueTime, ui.RecentPayTime, ui.Mid, ui.Ver); err != nil {51 log.Error("tx.Exec(%s) error(%v)", _updateUserInfo, err)52 err = errors.WithStack(err)53 return54 }55 return56}57// TxUpdateUserInfo updates vip status of user.58func (d *Dao) TxUpdateUserStatus(ctx context.Context, tx *xsql.Tx, ui *model.UserInfo) (err error) {59 if _, err = tx.Exec(_updateUserStatus, ui.Status, ui.Mid, ui.Ver); err != nil {60 log.Error("tx.Exec(%s) error(%v)", _updateUserStatus, err)61 err = errors.WithStack(err)62 return63 }64 return65}66// TxUpdateUserPayType updates pay type of user.67func (d *Dao) TxUpdateUserPayType(ctx context.Context, tx *xsql.Tx, ui *model.UserInfo) (err error) {68 if _, err = tx.Exec(_updateUserPayType, ui.PayType, ui.Mid, ui.Ver); err != nil {69 log.Error("tx.Exec(%s) error(%v)", _updateUserPayType, err)70 err = errors.WithStack(err)71 return72 }73 return74}...

Full Screen

Full Screen

Info

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 err := termui.Init()4 if err != nil {5 panic(err)6 }7 defer termui.Close()8 termui.UseTheme("helloworld")9 p := termui.NewPar("Hello world")10 p2 := termui.NewPar("Hello world")11 p3 := termui.NewPar("Hello world")12 p4 := termui.NewPar("Hello world")13 p5 := termui.NewPar("Hello world")14 p6 := termui.NewPar("Hello world")15 p7 := termui.NewPar("Hello world")

Full Screen

Full Screen

Info

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 fmt.Println("Hello World")4}5import "fmt"6func main() {7 fmt.Println("Hello World")8}9import "fmt"10func main() {11 fmt.Println("Hello World")12}13import "fmt"14func main() {15 fmt.Println("Hello World")16}17import "fmt"18func main() {19 fmt.Println("Hello World")20}21import "fmt"22func main() {23 fmt.Println("Hello World")24}25import "fmt"26func main() {27 fmt.Println("Hello World")28}29import "fmt"30func main() {31 fmt.Println("Hello World")32}33import "fmt"34func main() {35 fmt.Println("Hello World")36}37import "fmt"38func main() {39 fmt.Println("Hello World")40}41import "fmt"42func main() {43 fmt.Println("Hello World")44}45import "fmt"46func main() {47 fmt.Println("Hello World")48}49import "fmt"50func main() {51 fmt.Println("Hello World")52}53import "fmt"54func main() {55 fmt.Println("Hello World")56}

Full Screen

Full Screen

Info

Using AI Code Generation

copy

Full Screen

1import "fmt"2import "ui"3func main() {4 fmt.Println(ui.Info())5}6import "fmt"7import "ui"8func main() {9 fmt.Println(ui.Info())10}11import "fmt"12import "ui"13func main() {14 fmt.Println(ui.Info())15}16import "fmt"17import "ui"18func main() {19 fmt.Println(ui.Info())20}21import "fmt"22import "ui"23func main() {24 fmt.Println(ui.Info())25}26import "fmt"27import "ui"28func main() {29 fmt.Println(ui.Info())30}31import "fmt"32import "ui"33func main() {34 fmt.Println(ui.Info())35}36import "fmt"37import "ui"38func main() {39 fmt.Println(ui.Info())40}41import "fmt"42import "ui"43func main() {44 fmt.Println(ui.Info())45}46import "fmt"47import "ui"48func main() {49 fmt.Println(ui.Info())50}51import "fmt"52import "ui"53func main() {54 fmt.Println(ui.Info())55}56import "fmt"57import "ui"58func main() {59 fmt.Println(ui.Info())60}61import "fmt"62import "ui"63func main() {64 fmt.Println(ui.Info())65}

Full Screen

Full Screen

Info

Using AI Code Generation

copy

Full Screen

1func main() {2 ui := ui.NewUI()3 ui.Info("Hello World")4}5func main() {6 ui := ui.NewUI()7 ui.Info("Hello World")8}9func main() {10 ui := ui.NewUI()11 ui.Info("Hello World")12}13func main() {14 ui := ui.NewUI()15 ui.Info("Hello World")16}17func main() {18 ui := ui.NewUI()19 ui.Info("Hello World")20}21func main() {22 ui := ui.NewUI()23 ui.Info("Hello World")24}25func main() {26 ui := ui.NewUI()27 ui.Info("Hello World")28}29func main() {30 ui := ui.NewUI()31 ui.Info("Hello World")32}33func main() {34 ui := ui.NewUI()35 ui.Info("Hello World")36}37func main() {38 ui := ui.NewUI()39 ui.Info("Hello World")40}41func main() {42 ui := ui.NewUI()43 ui.Info("Hello World")44}45func main() {46 ui := ui.NewUI()47 ui.Info("Hello World")48}49func main() {50 ui := ui.NewUI()51 ui.Info("Hello World")52}53func main() {54 ui := ui.NewUI()55 ui.Info("Hello World")56}

Full Screen

Full Screen

Info

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 ui := new(UI)4 ui.Info("Hello")5}6import "fmt"7type UI struct {8}9func (ui *UI) Info(msg string) {10 fmt.Println("Info:", msg)11}

Full Screen

Full Screen

Info

Using AI Code Generation

copy

Full Screen

1import "fmt"2type ui interface {3 Info()4}5type employee struct {6}7func (e employee) Info() {8 fmt.Println("Name:", e.name)9 fmt.Println("Age:", e.age)10}11func main() {12 e := employee{name: "John", age: 32}13 e.Info()14}15import "fmt"16type ui interface {17 Info()18}19type employee struct {20}21func (e employee) Info() {22 fmt.Println("Name:", e.name)23 fmt.Println("Age:", e.age)24}25func main() {26 e = employee{name: "John", age: 32}27 e.Info()28}29import "fmt"30type ui interface {31 Info()32}33type employee struct {34}35func (e employee) Info() {36 fmt.Println("Name:", e.name)37 fmt.Println("Age:", e.age)38}39func main() {40 e = employee{name: "John", age: 32}41 e.Info()42}43import "fmt"44type ui interface {45 Info()46}47type employee struct {48}49func (e employee) Info() {50 fmt.Println("Name:", e.name)51 fmt.Println("Age:", e.age)52}53func main() {54 e = employee{name: "John", age: 32}55 e.Info()56}57import "fmt"58type ui interface {59 Info()60}61type employee struct {62}63func (e employee) Info() {64 fmt.Println("Name:", e.name)65 fmt.Println("Age:", e.age)66}67func main() {

Full Screen

Full Screen

Info

Using AI Code Generation

copy

Full Screen

1import "fmt"2type ui interface {3 Info()4}5type person struct {6}7func (p *person) Info() {8 fmt.Printf("Name: %s, age: %d9}10func main() {11 p := person{"Raj", 23}12 p.Info()13}14import "fmt"15type ui interface {16 Info()17}18type person struct {19}20func (p *person) Info() {21 fmt.Printf("Name: %s, age: %d22}23func main() {24 p := person{"Raj", 23}25 i.Info()26}27import "fmt"28type ui interface {29 Info()30}31type person struct {32}33func (p *person) Info() {34 fmt.Printf("Name: %s, age: %d35}36func main() {37 p := person{"Raj", 23}38 i.Info()39 i.Info()40}41import "fmt"42type ui interface {43 Info()44}45type person struct {46}47func (p *person) Info() {48 fmt.Printf("Name: %s, age: %d49}50func main() {51 p := person{"Raj", 23}52 i.Info()53 i.Info()54 i = &person{"Raj", 23}55 i.Info()56}57import "fmt"58type ui interface {59 Info()60}61type person struct {62}63func (p *person) Info() {

Full Screen

Full Screen

Info

Using AI Code Generation

copy

Full Screen

1func main() {2 ui := GetUI()3 ui.Info("Hello world")4}5func main() {6 ui := GetUI()7 ui.Info("Hello world")8}9runtime.throw(0x4f2f2e, 0x15)10runtime.mapassign_faststr(0x4a7e40, 0xc0000b6000, 0x4f0d3e, 0x4, 0xc00007e8b8)11github.com/ankitjain28may/logger.(*UI).Info(0xc0000b6000, 0x4f0d3e, 0x4, 0xc00007e9a8, 0x1, 0x1)12main.main()

Full Screen

Full Screen

Info

Using AI Code Generation

copy

Full Screen

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

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