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

38
app/service/main/antispam/extern/BUILD vendored Normal file
View File

@@ -0,0 +1,38 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
)
go_library(
name = "go_default_library",
srcs = [
"client.go",
"handler.go",
"mock.go",
"reply_service.go",
],
importpath = "go-common/app/service/main/antispam/extern",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/service/main/antispam/conf:go_default_library",
"//library/log:go_default_library",
"//library/net/http/blademaster: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,31 @@
package extern
import (
"go-common/app/service/main/antispam/conf"
bm "go-common/library/net/http/blademaster"
)
type Client struct {
*ReplyServiceClient
}
func NewClient(c *conf.Config) *Client {
httpCli := bm.NewClient(c.HTTPClient)
return &Client{
ReplyServiceClient: &ReplyServiceClient{
host: c.ReplyURL,
commonClient: &commonClient{
httpCli: httpCli,
key: c.App.Key,
secret: c.App.Secret,
},
},
}
}
type commonClient struct {
httpCli *bm.Client
key, secret string
}

View File

@@ -0,0 +1,11 @@
package extern
import "context"
type Handler interface {
ReplyHandler
}
type ReplyHandler interface {
DeleteReply(ctx context.Context, adminId int64, rs []*Reply) error
}

View File

@@ -0,0 +1,11 @@
package extern
import "context"
type MockExternHandler struct {
ErrDeleteReply error
}
func (mf *MockExternHandler) DeleteReply(ctx context.Context, adminID int64, ks []*Reply) error {
return mf.ErrDeleteReply
}

View File

@@ -0,0 +1,98 @@
package extern
import (
"context"
"fmt"
"net/url"
"path"
"time"
"go-common/library/log"
)
const (
PathDeleteReplyByIds = "/x/internal/v2/reply/del"
)
type Reply struct {
Id int64 `json:"id"`
OId int64 `json:"oid"`
OType int64 `json:"typ"`
}
var replySvrCli *ReplyServiceClient
type ReplyServiceClient struct {
*commonClient
host string
}
type ReplyServiceResp struct {
Code int `json:"code"`
Message string `json:"messge"`
Data interface{} `json:"data"`
}
type Replys []*Reply
func (rs Replys) OIds() string {
var s string
for _, r := range rs {
s += fmt.Sprintf("%d,", r.OId)
}
return s
}
func (rs Replys) Ids() string {
var s string
for _, r := range rs {
s += fmt.Sprintf("%d,", r.Id)
}
return s[:len(s)-1]
}
func (rs Replys) OTypes() string {
var s string
for _, r := range rs {
s += fmt.Sprintf("%d,", r.OType)
}
return s[:len(s)-1]
}
func (self *ReplyServiceClient) DeleteReply(ctx context.Context, adminId int64, rs []*Reply) error {
val := url.Values{}
val.Add("adid", fmt.Sprintf("%d", adminId))
val.Add("adname", "antispam")
val.Add("oid", Replys(rs).OIds())
val.Add("rpid", Replys(rs).Ids())
val.Add("type", Replys(rs).OTypes())
val.Add("moral", "0")
val.Add("notify", "false")
val.Add("remark", "")
val.Add("ftime", "")
val.Add("reason", "delete by antispam")
return self.do(ctx, PathDeleteReplyByIds, val, &ReplyServiceResp{}, replySvrCli.httpCli.Post)
}
func (rs *ReplyServiceClient) do(ctx context.Context,
urlPath string, params url.Values, resp *ReplyServiceResp,
fn func(ctx context.Context, uri string, ip string, params url.Values, resp interface{}) error,
) error {
params.Set("appkey", rs.key)
params.Set("appsecret", rs.secret)
params.Set("ts", fmt.Sprintf("%d", time.Now().Unix()+int64(10)))
urlAddr := path.Join(rs.host + urlPath)
err := fn(ctx, urlAddr, "", params, resp)
if err != nil {
return err
}
if resp.Code != 0 {
err = fmt.Errorf("Call reply service(%s), response code is not 0, resp:%v", urlAddr+"?"+params.Encode(), resp)
log.Error("%v", err)
return err
}
log.Info("Call reply service(%s) successful, resp: %v", urlAddr+"?"+params.Encode(), resp)
return nil
}