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,49 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_test",
"go_library",
)
go_test(
name = "go_default_test",
srcs = ["community_test.go"],
embed = [":go_default_library"],
rundir = ".",
tags = ["automanaged"],
deps = [
"//app/interface/main/app-interface/conf:go_default_library",
"//vendor/github.com/smartystreets/goconvey/convey:go_default_library",
],
)
go_library(
name = "go_default_library",
srcs = ["dao.go"],
importpath = "go-common/app/interface/main/app-interface/dao/community",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/interface/main/app-interface/conf:go_default_library",
"//app/interface/main/app-interface/model/community:go_default_library",
"//library/ecode:go_default_library",
"//library/net/http/blademaster:go_default_library",
"//library/net/metadata: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,35 @@
package community
import (
"context"
"encoding/json"
"fmt"
"testing"
"go-common/app/interface/main/app-interface/conf"
. "github.com/smartystreets/goconvey/convey"
)
// go test -conf="../../app-interface-example.toml" -v -test.run TestCommunity
func TestCommunity(t *testing.T) {
Convey("TestCommuity", t, func() {
})
err := conf.Init()
if err != nil {
return
}
dao := New(conf.Conf)
community, _, err := dao.Community(context.TODO(), 28009145, "2e3950631afd879592de5e2ee34c7293", "android", 1, 20)
if err != nil {
t.Errorf("dao.Community error(%v)", err)
return
}
result, err := json.Marshal(community)
if err != nil {
t.Errorf("json.Marshal error(%v)", err)
return
}
fmt.Printf("test community (%v) \n", string(result))
}

View File

@@ -0,0 +1,66 @@
package community
import (
"context"
"net/url"
"strconv"
"go-common/app/interface/main/app-interface/conf"
"go-common/app/interface/main/app-interface/model/community"
"go-common/library/ecode"
httpx "go-common/library/net/http/blademaster"
"go-common/library/net/metadata"
"github.com/pkg/errors"
)
const (
_comm = "/api/query.my.community.list.do"
)
// Dao is community dao
type Dao struct {
client *httpx.Client
community string
}
// New initial community dao
func New(c *conf.Config) (d *Dao) {
d = &Dao{
client: httpx.NewClient(c.HTTPIm9),
community: c.Host.Im9 + _comm,
}
return
}
// Community get community data from api.
func (d *Dao) Community(c context.Context, mid int64, ak, platform string, pn, ps int) (co []*community.Community, count int, err error) {
ip := metadata.String(c, metadata.RemoteIP)
params := url.Values{}
params.Set("actionKey", "appkey")
params.Set("data_type", "2")
params.Set("access_key", ak)
params.Set("mid", strconv.FormatInt(mid, 10))
params.Set("page_no", strconv.Itoa(pn))
params.Set("page_size", strconv.Itoa(ps))
params.Set("platform", platform)
var res struct {
Code int `json:"code"`
Data *struct {
Count int `json:"total_count"`
Result []*community.Community `json:"result"`
} `json:"data"`
}
if err = d.client.Get(c, d.community, ip, params, &res); err != nil {
return
}
if res.Code != ecode.OK.Code() {
err = errors.Wrap(ecode.Int(res.Code), d.community+"?"+params.Encode())
return
}
if res.Data != nil {
co = res.Data.Result
count = res.Data.Count
}
return
}