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,74 @@
load(
"@io_bazel_rules_go//proto:def.bzl",
"go_proto_library",
)
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_test",
"go_library",
)
proto_library(
name = "v1_proto",
srcs = ["api.proto"],
tags = ["automanaged"],
deps = ["@gogo_special_proto//github.com/gogo/protobuf/gogoproto"],
)
go_proto_library(
name = "v1_go_proto",
compilers = ["@io_bazel_rules_go//proto:gogofast_grpc"],
importpath = "go-common/app/interface/main/creative/api",
proto = ":v1_proto",
tags = ["automanaged"],
deps = ["@com_github_gogo_protobuf//gogoproto:go_default_library"],
)
go_test(
name = "go_default_test",
srcs = ["client_test.go"],
embed = [":go_default_library"],
tags = ["automanaged"],
deps = [
"//library/log:go_default_library",
"//library/naming/discovery:go_default_library",
"//library/net/netutil/breaker:go_default_library",
"//library/net/rpc/warden:go_default_library",
"//library/net/rpc/warden/resolver:go_default_library",
"//library/time:go_default_library",
"//vendor/github.com/smartystreets/goconvey/convey:go_default_library",
],
)
go_library(
name = "go_default_library",
srcs = ["client.go"],
embed = [":v1_go_proto"],
importpath = "go-common/app/interface/main/creative/api",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//library/net/rpc/warden:go_default_library",
"@com_github_gogo_protobuf//gogoproto:go_default_library",
"@com_github_gogo_protobuf//proto:go_default_library",
"@org_golang_google_grpc//:go_default_library",
"@org_golang_x_net//context: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"],
)

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,42 @@
syntax = "proto3";
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
package main.archive.creative;
option go_package = "v1";
// Creative grpc
service Creative {
// FlowJudge 查询flow情况
rpc FlowJudge(FlowRequest) returns(FlowResponse);
// Sends a greeting
rpc CheckTaskState (TaskRequest) returns (TaskReply) {}
// Ping Service
rpc Ping(Empty) returns(Empty);
// Close Service
rpc Close(Empty) returns(Empty);
}
message FlowRequest {
int64 gid = 1;
int64 business = 2;
repeated int64 oids = 3;
}
message FlowResponse {
repeated int64 oids = 1;
}
// The request message containing the user's name.
message TaskRequest {
int64 mid = 1;
int64 task_id = 2;
}
// The response message containing the greetings
message TaskReply {
bool finish_state = 1;
}
message Empty{}

View File

@@ -0,0 +1,24 @@
package v1
import (
"context"
"fmt"
"go-common/library/net/rpc/warden"
"google.golang.org/grpc"
)
// DiscoveryAppID .
const DiscoveryAppID = "main.archive.creative"
// NewClient new grpc client
func NewClient(cfg *warden.ClientConfig, opts ...grpc.DialOption) (CreativeClient, error) {
client := warden.NewClient(cfg, opts...)
// cc, err := client.Dial(context.Background(), "127.0.0.1:9000")
cc, err := client.Dial(context.Background(), fmt.Sprintf("discovery://default/%s", DiscoveryAppID))
if err != nil {
return nil, err
}
return NewCreativeClient(cc), nil
}

View File

@@ -0,0 +1,66 @@
package v1
import (
"context"
"testing"
"time"
"go-common/library/log"
"go-common/library/naming/discovery"
"go-common/library/net/netutil/breaker"
"go-common/library/net/rpc/warden"
"go-common/library/net/rpc/warden/resolver"
xtime "go-common/library/time"
"github.com/smartystreets/goconvey/convey"
)
func testInit() CreativeClient {
log.Init(nil)
conf := &warden.ClientConfig{
Dial: xtime.Duration(time.Second * 10),
Timeout: xtime.Duration(time.Second * 10),
Breaker: &breaker.Config{
Window: xtime.Duration(3 * time.Second),
Sleep: xtime.Duration(3 * time.Second),
Bucket: 10,
Ratio: 0.3,
Request: 20,
},
}
wc := warden.NewClient(conf)
resolver.Register(discovery.New(nil))
conn, err := wc.Dial(context.TODO(), "127.0.0.1:9000")
if err != nil {
panic(err)
}
return NewCreativeClient(conn)
}
//var client CreativeClient
//
//func init() {
// var err error
// client, err = NewClient(nil)
// if err != nil {
// panic(err)
// }
//}
func TestFlowJudge(t *testing.T) {
client := testInit()
convey.Convey("TestFlowJudge", t, func(ctx convey.C) {
ctx.Convey("When everything is correct", func(ctx convey.C) {
oids, err := client.FlowJudge(context.TODO(), &FlowRequest{Business: int64(4), Gid: int64(24), Oids: []int64{22, 333, 10110208, 10110119}})
ctx.So(err, convey.ShouldBeNil)
ctx.Printf("%+v\n", oids.Oids)
})
//ctx.Convey("When error", func(ctx convey.C) {
//})
})
}
func TestCheckTaskState(t *testing.T) {
client := testInit()
client.CheckTaskState(context.TODO(), &TaskRequest{Mid: int64(1), TaskId: int64(1)})
}