How to use Protect method of protect Package

Best Selenoid code snippet using protect.Protect

mysql_protect.go

Source:mysql_protect.go Github

copy

Full Screen

...11 "go-common/library/xstr"12)13const (14 // dm protect apply15 _addProtect = "INSERT INTO dm_protect_apply (cid, uid, apply_uid, aid, playtime, dmid, msg, status, ctime, mtime) VALUES %s"16 _selProtect = "SELECT ctime FROM dm_protect_apply WHERE dmid=? ORDER BY id DESC"17 _getPrttApply = "SELECT id,cid,apply_uid,aid,playtime,msg,ctime from dm_protect_apply where uid=? %s and status=-1"18 _getProtectAids = "SELECT aid FROM dm_protect_apply WHERE uid=? GROUP BY aid"19 _paStatus = "UPDATE dm_protect_apply SET status=%d WHERE uid=%d AND id IN (%s)"20 _chgPaSwitch = "INSERT INTO dm_protect_up (uid, notice_switch) VALUES(?, ?) ON DUPLICATE KEY UPDATE notice_switch=?"21 _getProtectByIDs = "SELECT cid,dmid FROM dm_protect_apply WHERE uid=%d AND id IN (%s)"22 _paUsrStat = "SELECT aid,apply_uid,status,ctime from dm_protect_apply where ctime>?"23 _paStatistics = "SELECT uid from dm_protect_apply where status=-1 GROUP BY uid"24 _paNoticeSwitch = "SELECT uid FROM dm_protect_up WHERE uid IN (%s) AND notice_switch=0"25)26// AddProtectApply 添加保护弹幕申请27func (d *Dao) AddProtectApply(c context.Context, pas []*model.Pa) (affect int64, err error) {28 var (29 values, s string30 )31 for _, pa := range pas {32 pa.Msg = strings.Replace(pa.Msg, `\`, `\\`, -1)33 pa.Msg = strings.Replace(pa.Msg, `'`, `\'`, -1)34 values += fmt.Sprintf(`(%d, %d, %d, %d, %f, %d, '%s', %d, '%s', '%s'),`, pa.CID, pa.UID, pa.ApplyUID, pa.AID, pa.Playtime, pa.DMID, pa.Msg, pa.Status, pa.Ctime.Format("2006-01-02 15:04:05"), pa.Mtime.Format("2006-01-02 15:04:05"))35 }36 if len(values) > 0 {37 values = values[0:(len(values) - 1)]38 }39 s = fmt.Sprintf(_addProtect, values)40 res, err := d.biliDM.Exec(c, s)41 if err != nil {42 log.Error("d.biliDM.Exec(%v) error(%v)", s, err)43 return44 }45 affect, err = res.RowsAffected()46 return47}48// ProtectApplyTime 根据dmid获取保护弹幕申请49func (d *Dao) ProtectApplyTime(c context.Context, dmid int64) (t time.Time, err error) {50 row := d.biliDM.QueryRow(c, _selProtect, dmid)51 if err = row.Scan(&t); err != nil {52 if err == sql.ErrNoRows {53 err = nil54 } else {55 log.Error("row.Scan error(%v)", err)56 }57 }58 return59}60// ProtectApplies 保护弹幕申请列表61func (d *Dao) ProtectApplies(c context.Context, uid, aid int64, order string) (res []*model.Apply, err error) {62 var (63 query string64 rows *sql.Rows65 )66 if aid > 0 {67 query = fmt.Sprintf(_getPrttApply, "AND aid=?")68 rows, err = d.biliDM.Query(c, query, uid, aid)69 } else {70 query = fmt.Sprintf(_getPrttApply, "")71 rows, err = d.biliDM.Query(c, query, uid)72 }73 if err != nil {74 log.Error("d.biliDM.Query(%s,%v,%v) error(%v)", query, uid, aid, err)75 return76 }77 defer rows.Close()78 for rows.Next() {79 r := &model.Apply{}80 t := time.Time{}81 if err = rows.Scan(&r.ID, &r.CID, &r.ApplyUID, &r.AID, &r.Playtime, &r.Msg, &t); err != nil {82 log.Error("rows.Scan error(%v)", err)83 return84 }85 r.Ctime = t.Format("2006-01-02 15:04:05")86 res = append(res, r)87 }88 if err = rows.Err(); err != nil {89 log.Error("rows.Err() error(%v)", err)90 return91 }92 if order == "playtime" {93 sort.Sort(model.ApplySortPlaytime(res))94 } else {95 sort.Sort(model.ApplySortID(res))96 }97 return98}99// ProtectAids 被申请保护弹幕稿件列表100func (d *Dao) ProtectAids(c context.Context, uid int64) (res []int64, err error) {101 rows, err := d.biliDM.Query(c, _getProtectAids, uid)102 if err != nil {103 log.Error("d.biliDM.Query(%s,%d) error(%v)", _getProtectAids, uid, err)104 return105 }106 defer rows.Close()107 for rows.Next() {108 var aid int64109 if err = rows.Scan(&aid); err != nil {110 log.Error("rows.Scan error(%v)", err)111 return112 }113 res = append(res, aid)114 }115 if err = rows.Err(); err != nil {116 log.Error("rows.Err() error(%v)", err)117 }118 return119}120// UptPaStatus 修改保护弹幕状态121func (d *Dao) UptPaStatus(c context.Context, uid int64, ids string, status int) (affect int64, err error) {122 s := fmt.Sprintf(_paStatus, status, uid, ids)123 res, err := d.biliDM.Exec(c, s)124 if err != nil {125 log.Error("d.biliDM.Exec(%v) error(%v)", s, err)126 }127 affect, err = res.RowsAffected()128 return129}130// ProtectApplyByIDs get protect apply by dmid131func (d *Dao) ProtectApplyByIDs(c context.Context, uid int64, ids string) (res map[int64][]int64, err error) {132 res = make(map[int64][]int64, 10)133 s := fmt.Sprintf(_getProtectByIDs, uid, ids)134 rows, err := d.biliDM.Query(c, s)135 if err != nil {136 log.Error("d.biliDM.Query(%s) error(%v)", s, err)137 return138 }139 defer rows.Close()140 for rows.Next() {141 var (142 dmid int64143 cid int64144 )145 if err = rows.Scan(&cid, &dmid); err != nil {146 log.Error("rows.Scan error(%v)", err)147 return148 }149 _, ok := res[cid]150 if ok {151 res[cid] = append(res[cid], dmid)152 } else {153 res[cid] = []int64{dmid}154 }155 }156 if err = rows.Err(); err != nil {157 log.Error("rows.Err() error(%v)", err)158 }159 return160}161// UptPaNoticeSwitch 设置申请保护弹幕站内通知开关162func (d *Dao) UptPaNoticeSwitch(c context.Context, uid int64, status int) (affect int64, err error) {163 res, err := d.biliDM.Exec(c, _chgPaSwitch, uid, status, status)164 if err != nil {165 log.Error("d.biliDM.Exec(%s,%d,%d) error(%v)", _chgPaSwitch, status, uid, err)166 }167 affect, err = res.RowsAffected()168 return169}170// PaNoticeClose 获取关闭申请保护弹幕站内通知171func (d *Dao) PaNoticeClose(c context.Context, uids []int64) (res map[int64]bool, err error) {172 if len(uids) < 1 {173 return174 }175 res = make(map[int64]bool, len(uids))176 s := fmt.Sprintf(_paNoticeSwitch, xstr.JoinInts(uids))177 rows, err := d.biliDM.Query(c, s)178 if err != nil {179 log.Error("d.biliDM.Query(%s) error(%v)", s, err)180 return181 }182 defer rows.Close()183 for rows.Next() {184 var uid int64185 if err = rows.Scan(&uid); err != nil {186 log.Error("rows.Scan error(%v)", err)187 return188 }189 res[uid] = true190 }191 if err = rows.Err(); err != nil {192 log.Error("rows.Err() error(%v)", err)193 }194 return195}196// ProtectApplyStatistics 保护弹幕申请up统计197func (d *Dao) ProtectApplyStatistics(c context.Context) (res []int64, err error) {198 rows, err := d.biliDM.Query(c, _paStatistics)199 if err != nil {200 log.Error("d.biliDM.Query(%s) error(%v)", _paStatistics, err)201 return202 }203 defer rows.Close()204 for rows.Next() {205 var uid int64206 if err = rows.Scan(&uid); err != nil {207 log.Error("rows.Scan error(%v)", err)208 return209 }210 res = append(res, uid)211 }...

Full Screen

Full Screen

protect.go

Source:protect.go Github

copy

Full Screen

...8 "go-common/library/ecode"9 "go-common/library/log"10)11const (12 _dmProtectApplyListURI = "/x/internal/dm/up/protect/apply/list"13 _dmProtectApplyStatusURI = "/x/internal/dm/up/protect/apply/status"14 _dmProtectApplyVideoListURI = "/x/internal/dm/up/protect/apply/video/list"15)16// ProtectApplyList fn17func (d *Dao) ProtectApplyList(c context.Context, mid, page int64, aidStr, sort, ip string) (result *danmu.ApplyList, err error) {18 result = &danmu.ApplyList{}19 params := url.Values{}20 params.Set("uid", strconv.FormatInt(mid, 10))21 params.Set("aid", aidStr)22 params.Set("page", strconv.FormatInt(page, 10))23 params.Set("sort", sort)24 var res struct {25 Code int `json:"code"`26 Data *danmu.ApplyListFromDM `json:"data"`27 }28 if err = d.client.Get(c, d.dmProtectApplyListURL, ip, params, &res); err != nil {29 err = ecode.CreativeDanmuErr30 log.Error("d.ProtectApplyList.Get(%s,%s,%s) err(%v)", d.dmProtectApplyListURL, ip, params.Encode(), err)31 return32 }33 if res.Code != 0 {34 err = ecode.Int(res.Code)35 log.Error("d.ProtectApplyList.Get(%s,%s,%s) err(%v)|code(%d)", d.dmProtectApplyListURL, ip, params.Encode(), err, res.Code)36 return37 }38 for _, v := range res.Data.List {39 v.IDStr = strconv.FormatInt(v.ID, 10)40 }41 result = &danmu.ApplyList{42 Pager: res.Data.Pager,43 List: res.Data.List,44 }45 return46}47// ProtectApplyVideoList fn48func (d *Dao) ProtectApplyVideoList(c context.Context, mid int64, ip string) (result []*dmMdl.Video, err error) {49 result = []*dmMdl.Video{}50 params := url.Values{}51 params.Set("uid", strconv.FormatInt(mid, 10))52 var res struct {53 Code int `json:"code"`54 Data []*dmMdl.Video `json:"data"`55 }56 if err = d.client.Get(c, d.dmProtectApplyVideoListURL, ip, params, &res); err != nil {57 err = ecode.CreativeDanmuErr58 log.Error("d.ProtectApplyVideoList.Get(%s,%s,%s) err(%v)", d.dmProtectApplyVideoListURL, ip, params.Encode(), err)59 return60 }61 if res.Code != 0 {62 err = ecode.Int(res.Code)63 log.Error("d.ProtectApplyVideoList.Get(%s,%s,%s) err(%v)|code(%d)", d.dmProtectApplyVideoListURL, ip, params.Encode(), err, res.Code)64 return65 }66 result = res.Data67 return68}69// ProtectOper fn70func (d *Dao) ProtectOper(c context.Context, mid, status int64, ids, ip string) (err error) {71 params := url.Values{}72 params.Set("uid", strconv.FormatInt(mid, 10))73 params.Set("status", strconv.FormatInt(status, 10))74 params.Set("ids", ids)75 var res struct {76 Code int `json:"code"`77 }78 if err = d.client.Post(c, d.dmProtectApplyStatusURL, ip, params, &res); err != nil {79 err = ecode.CreativeDanmuErr80 log.Error("d.ProtectApply.Post(%s,%s,%s) err(%v)", d.dmProtectApplyStatusURL, ip, params.Encode(), err)81 return82 }83 if res.Code != 0 {84 err = ecode.Int(res.Code)85 log.Error("d.ProtectApply.Post(%s,%s,%s) err(%v)|code(%d)", d.dmProtectApplyStatusURL, ip, params.Encode(), err, res.Code)86 return87 }88 return89}...

Full Screen

Full Screen

Protect

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 p.Protect()4 fmt.Println("Path: 1.go")5 fmt.Println("code to use Protect method of protect class")6}

Full Screen

Full Screen

Protect

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello, playground")4 p := protect.NewProtect()5 p.Protect()6}

Full Screen

Full Screen

Protect

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 p := protect.Protect{}4 p.Protect()5 fmt.Println("main function")6}

Full Screen

Full Screen

Protect

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello, playground")4 p := protect.Protect{}5 p.Protect()6}

Full Screen

Full Screen

Protect

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 p := protect.Protect{}4 fmt.Println("Protected field value is", p.Protected)5 p.Protect()6}

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.

Run Selenoid automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful