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,47 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_test",
"go_library",
)
go_test(
name = "go_default_test",
srcs = ["shopping_test.go"],
embed = [":go_default_library"],
rundir = ".",
tags = ["automanaged"],
deps = [
"//app/interface/main/app-wall/conf:go_default_library",
"//vendor/github.com/smartystreets/goconvey/convey:go_default_library",
],
)
go_library(
name = "go_default_library",
srcs = ["shopping.go"],
importpath = "go-common/app/interface/main/app-wall/dao/shopping",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/interface/main/app-wall/conf:go_default_library",
"//library/ecode: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,72 @@
package shopping
import (
"bytes"
"context"
"encoding/json"
"net/http"
"go-common/app/interface/main/app-wall/conf"
"go-common/library/ecode"
"go-common/library/log"
httpx "go-common/library/net/http/blademaster"
)
const (
_couponURL = "/mall-marketing/coupon_code/create"
)
// Dao is shopping dao
type Dao struct {
client *httpx.Client
couponURL string
}
// New shopping dao.
func New(c *conf.Config) (d *Dao) {
d = &Dao{
client: httpx.NewClient(c.HTTPClient),
// url
couponURL: c.Host.Mall + _couponURL,
}
return
}
// Coupon user vip
func (d *Dao) Coupon(c context.Context, couponID string, mid int64, uname string) (msg string, err error) {
var res struct {
Code int `json:"code"`
Msg string `json:"message"`
}
data := map[string]interface{}{
"couponId": couponID,
"mid": mid,
"uname": uname,
}
var (
bytesData []byte
req *http.Request
)
if bytesData, err = json.Marshal(data); err != nil {
log.Error("json.Marshal error(%v)", err)
return
}
if req, err = http.NewRequest("POST", d.couponURL, bytes.NewReader(bytesData)); err != nil {
log.Error("http.NewRequest error(%v)", err)
return
}
req.Header.Set("Content-Type", "application/json;charset=UTF-8")
req.Header.Set("X-BACKEND-BILI-REAL-IP", "")
log.Info("coupon vip mid(%d) couponID(%s)", mid, couponID)
if err = d.client.Do(c, req, &res); err != nil {
log.Error("coupon vip url(%v) error(%v)", d.couponURL, err)
return
}
msg = res.Msg
if res.Code != 0 {
err = ecode.Int(res.Code)
log.Error("coupon vip url(%v) res code(%d)", d.couponURL, res.Code)
return
}
return
}

View File

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