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,48 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_test",
"go_library",
)
go_test(
name = "go_default_test",
srcs = ["bplus_test.go"],
embed = [":go_default_library"],
rundir = ".",
tags = ["automanaged"],
deps = [
"//app/interface/main/app-resource/conf:go_default_library",
"//vendor/github.com/smartystreets/goconvey/convey:go_default_library",
],
)
go_library(
name = "go_default_library",
srcs = ["bplus.go"],
importpath = "go-common/app/interface/main/app-resource/dao/bplus",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/interface/main/app-resource/conf:go_default_library",
"//library/ecode:go_default_library",
"//library/log:go_default_library",
"//library/net/http/blademaster:go_default_library",
"//vendor/github.com/pkg/errors: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,61 @@
package bplus
import (
"context"
"encoding/json"
"net/url"
"strconv"
"go-common/app/interface/main/app-resource/conf"
"go-common/library/ecode"
"go-common/library/log"
httpx "go-common/library/net/http/blademaster"
"github.com/pkg/errors"
)
const (
_checkUser = "/promo_svr/v0/promo_svr/inner_user_check"
)
// Dao bplus
type Dao struct {
client *httpx.Client
// url
checkUserURL string
}
// New bplus
func New(c *conf.Config) (d *Dao) {
d = &Dao{
client: httpx.NewClient(c.HTTPClient),
// url
checkUserURL: c.Host.VC + _checkUser,
}
return
}
// UserCheck 动态互推入口白名单
func (d *Dao) UserCheck(c context.Context, mid int64) (ok bool, err error) {
params := url.Values{}
params.Set("uid", strconv.FormatInt(mid, 10))
var res struct {
Code int `json:"code"`
Data struct {
Status int `json:"status"`
}
}
if err = d.client.Get(c, d.checkUserURL, "", params, &res); err != nil {
return
}
b, _ := json.Marshal(&res)
log.Info("UserCheck url(%s) response(%s)", d.checkUserURL+"?"+params.Encode(), b)
if res.Code != ecode.OK.Code() {
err = errors.Wrap(ecode.Int(res.Code), d.checkUserURL+"?"+params.Encode())
return
}
if res.Data.Status == 1 {
ok = true
}
return
}

View File

@@ -0,0 +1,37 @@
package bplus
import (
"context"
"flag"
"path/filepath"
"testing"
"time"
"go-common/app/interface/main/app-resource/conf"
. "github.com/smartystreets/goconvey/convey"
)
var (
d *Dao
)
func ctx() context.Context {
return context.Background()
}
func init() {
dir, _ := filepath.Abs("../../cmd/app-resource-test.toml")
flag.Set("conf", dir)
conf.Init()
d = New(conf.Conf)
time.Sleep(time.Second)
}
func TestUserCheck(t *testing.T) {
Convey("get UserCheck all", t, func() {
res, err := d.UserCheck(ctx(), 1)
So(err, ShouldBeNil)
So(res, ShouldNotBeEmpty)
})
}