Create & Init Project...

This commit is contained in:
2019-04-22 18:49:16 +08:00
commit fc4fa37393
25440 changed files with 4054998 additions and 0 deletions

View File

@@ -0,0 +1,35 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
)
go_library(
name = "go_default_library",
srcs = [
"common.go",
"keyword.go",
"regexp.go",
"rule.go",
"suspicious.go",
],
importpath = "go-common/app/service/main/antispam/model",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = ["//app/service/main/antispam/util:go_default_library"],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

View File

@@ -0,0 +1,33 @@
package model
const (
// ID .
ID = "id"
// Area .
Area = "area"
// AreaReply .
AreaReply = "reply"
// AreaIMessage .
AreaIMessage = "im"
// AreaLiveDM .
AreaLiveDM = "live_dm"
// AreaMainSiteDM .
AreaMainSiteDM = "danmu"
// State .
State = "state"
// StateDefault .
StateDefault = "default"
// StateDeleted .
StateDeleted = "deleted"
// OrderASC .
OrderASC = "ASC"
// OrderDESC .
OrderDESC = "DESC"
// CTime .
CTime = "ctime"
// MTime .
MTime = "mtime"
)

View File

@@ -0,0 +1,54 @@
package model
import (
"fmt"
"go-common/app/service/main/antispam/util"
)
const (
// ParamKeywordHitCounts .
ParamKeywordHitCounts = "show_up_counts"
// KeywordTag .
KeywordTag = "tag"
// KeywordTagBlack .
KeywordTagBlack = "black"
// KeywordTagWhite .
KeywordTagWhite = "white"
// KeywordTagDefaultLimit .
KeywordTagDefaultLimit = "limit"
// KeywordTagRestrictLimit .
KeywordTagRestrictLimit = "restrict"
// KeywordContent .
KeywordContent = "content"
// KeywordHitCounts .
KeywordHitCounts = "hit_counts"
)
// SenderList .
type SenderList struct {
SenderIDs []int64 `json:"sender_ids"`
Counts int `json:"counts"`
}
// Keyword .
type Keyword struct {
ID int64 `json:"id"`
Area string `json:"-"`
Content string `json:"content"`
SenderID int64 `json:"-"`
OriginContent string `json:"origin_content"`
SenderCounts int64 `json:"sender_counts"`
RegexpName string `json:"reg_name"`
Tag string `json:"tag"`
State string `json:"state"`
HitCounts int64 `json:"show_up_counts"`
CTime util.JSONTime `json:"ctime"`
MTime util.JSONTime `json:"mtime"`
}
func (k *Keyword) String() string {
return fmt.Sprintf("id: %d, area: %s, content: %s, tag: %s, state: %s, hitCounts %d\n",
k.ID, k.Area, k.Content, k.Tag, k.State, k.HitCounts)
}

View File

@@ -0,0 +1,48 @@
package model
import (
"fmt"
"regexp"
"strings"
"go-common/app/service/main/antispam/util"
)
const (
// OperationLimit .
OperationLimit = "limit"
// OperationRestrictLimit .
OperationRestrictLimit = "restrict"
// OperationPutToWhiteList .
OperationPutToWhiteList = "white"
// OperationIgnore .
OperationIgnore = "ignore"
)
// Regexp .
type Regexp struct {
ID int64 `json:"id"`
Area string `json:"area"`
AdminID int64 `json:"admin_id"`
AdminName string `json:"-"`
Reg *regexp.Regexp `json:"-"`
Name string `json:"name"`
Operation string `json:"op"`
Content string `json:"content"`
State string `json:"state"`
CTime util.JSONTime `json:"-"`
MTime util.JSONTime `json:"mtime"`
}
// FindString .
func (r *Regexp) FindString(content string) string {
if hits := r.Reg.FindStringSubmatch(content); len(hits) >= 2 {
return strings.TrimSpace(hits[1])
}
return ""
}
func (r *Regexp) String() string {
return fmt.Sprintf("name:%s, operation:%s, regexp:%s\n",
r.Name, r.Operation, r.Content)
}

View File

@@ -0,0 +1,38 @@
package model
const (
// LimitTypeDefault .
LimitTypeDefault = "limit"
// LimitTypeRestrict .
LimitTypeRestrict = "restrict"
// LimitTypeBlack .
LimitTypeBlack = "black"
// LimitTypeWhite .
LimitTypeWhite = "white"
// LimitScopeLocal .
LimitScopeLocal = "local"
// LimitScopeGlobal .
LimitScopeGlobal = "global"
)
// AggregateRule .
type AggregateRule struct {
Area string `json:"area"`
LimitType string `json:"limit_type"`
GlobalAllowedCounts int64 `json:"global_allowed_counts"`
LocalAllowedCounts int64 `json:"local_allowed_counts"`
GlobalDurationSec int64 `json:"global_dur"`
LocalDurationSec int64 `json:"local_dur"`
}
// Rule .
type Rule struct {
ID int64 `json:"id"`
Area string `json:"area"`
AllowedCounts int64 `json:"allowed_counts"`
LimitType string `json:"limit_type"`
LimitScope string `json:"limit_scope"`
DurationSec int64 `json:"dur"`
}

View File

@@ -0,0 +1,42 @@
package model
// Suspicious .
type Suspicious struct {
Id int64 `json:"id"`
SenderId int64 `json:"sender_id"`
Content string `json:"content"`
Area string `json:"area"`
OId int64 `json:"oid"`
}
// GetArea .
func (susp *Suspicious) GetArea() string {
return susp.Area
}
// GetSenderID .
func (susp *Suspicious) GetSenderID() int64 {
return susp.SenderId
}
// GetID .
func (susp *Suspicious) GetID() int64 {
return susp.Id
}
// GetOID .
func (susp *Suspicious) GetOID() int64 {
return susp.OId
}
// GetContent .
func (susp *Suspicious) GetContent() string {
return susp.Content
}
// SuspiciousResp .
type SuspiciousResp struct {
Area string `json:"-"`
Content string `json:"content"`
LimitType string `json:"susp_type"`
}