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,52 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
"go_test",
)
go_library(
name = "go_default_library",
srcs = [
"dao.go",
"send.go",
],
importpath = "go-common/app/admin/main/growup/dao/message",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/admin/main/growup/conf:go_default_library",
"//library/log:go_default_library",
"//library/net/http/blademaster:go_default_library",
"//library/xstr: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"],
)
go_test(
name = "go_default_test",
srcs = [
"dao_test.go",
"send_test.go",
],
embed = [":go_default_library"],
tags = ["automanaged"],
deps = [
"//app/admin/main/growup/conf:go_default_library",
"//vendor/github.com/smartystreets/goconvey/convey:go_default_library",
],
)

View File

@@ -0,0 +1,24 @@
package message
import (
"go-common/app/admin/main/growup/conf"
xhttp "go-common/library/net/http/blademaster"
)
// Dao is message dao
type Dao struct {
c *conf.Config
uri, creativeURL string
client *xhttp.Client
}
// New a message dao
func New(c *conf.Config) (d *Dao) {
d = &Dao{
c: c,
client: xhttp.NewClient(c.HTTPClient),
uri: c.Host.Message + "/api/notify/send.user.notify.do",
creativeURL: c.Host.Creative + "/x/internal/creative/join/growup/account",
}
return
}

View File

@@ -0,0 +1,34 @@
package message
import (
"flag"
"go-common/app/admin/main/growup/conf"
"os"
"testing"
)
var (
d *Dao
)
func TestMain(m *testing.M) {
if os.Getenv("DEPLOY_ENV") != "" {
flag.Set("app_id", "mobile.studio.growup-admin")
flag.Set("conf_token", "ac1fd397cbc33eb60541e8734844bdd5")
flag.Set("tree_id", "13583")
flag.Set("conf_version", "docker-1")
flag.Set("deploy_env", "uat")
flag.Set("conf_host", "config.bilibili.co")
flag.Set("conf_path", "/tmp")
flag.Set("region", "sh")
flag.Set("zone", "sh001")
} else {
flag.Set("conf", "../../cmd/growup-admin.toml")
}
flag.Parse()
if err := conf.Init(); err != nil {
panic(err)
}
d = New(conf.Conf)
os.Exit(m.Run())
}

View File

@@ -0,0 +1,66 @@
package message
import (
"context"
"fmt"
"net/url"
"strconv"
"strings"
"go-common/library/log"
"go-common/library/xstr"
)
// Send message to upper
func (d *Dao) Send(c context.Context, mc, title, msg string, mids []int64, ts int64) (err error) {
params := url.Values{}
source := strings.Split(mc, "_")
params.Set("type", "json")
params.Set("source", source[0])
params.Set("data_type", "4")
params.Set("mc", mc)
params.Set("title", title)
params.Set("context", msg)
var midList string
for _, mid := range mids {
midList += strconv.FormatInt(mid, 10)
midList += ","
}
midList = strings.TrimSuffix(midList, ",")
params.Set("mid_list", midList)
var res struct {
Code int `json:"code"`
}
log.Info("params:%v", params)
if err = d.client.Post(c, d.uri, "", params, &res); err != nil {
log.Error("growup-admin message url(%s) error(%v)", d.uri+"?"+params.Encode(), err)
return
}
log.Info("message res code:%d", res.Code)
if res.Code != 0 {
log.Error("growup-admin message url(%s) error(%v)", d.uri+"?"+params.Encode(), err)
err = fmt.Errorf("message send failed")
}
return
}
// NotifyTask notify task finish
func (d *Dao) NotifyTask(c context.Context, mids []int64) (err error) {
params := url.Values{}
params.Set("mids", xstr.JoinInts(mids))
var res struct {
Code int `json:"code"`
}
log.Info("creative notify task params:%v", params)
if err = d.client.Post(c, d.creativeURL, "", params, &res); err != nil {
log.Error("growup-admin creative notify task url(%s) error(%v)", d.creativeURL+"?"+params.Encode(), err)
return
}
log.Info("creative notify task res code:%d", res.Code)
if res.Code != 0 {
log.Error("growup-admin creative notify task url(%s) error(%v)", d.creativeURL+"?"+params.Encode(), err)
err = fmt.Errorf("creative notify task send failed")
}
return
}

View File

@@ -0,0 +1,43 @@
package message
import (
"context"
"testing"
"time"
"github.com/smartystreets/goconvey/convey"
)
func TestMessageSend(t *testing.T) {
convey.Convey("Send", t, func(ctx convey.C) {
var (
c = context.Background()
mc = "1_14_2"
title = "test"
msg = "test"
mids = []int64{253550886}
ts = time.Now().Unix()
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
err := d.Send(c, mc, title, msg, mids, ts)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestMessageNotifyTask(t *testing.T) {
convey.Convey("NotifyTask", t, func(ctx convey.C) {
var (
c = context.Background()
mids = []int64{2316310}
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
err := d.NotifyTask(c, mids)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldNotBeNil)
})
})
})
}