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,22 @@
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [
":package-srcs",
"//app/service/live/live_riskcontrol/api/grpc/v1:all-srcs",
"//app/service/live/live_riskcontrol/cmd:all-srcs",
"//app/service/live/live_riskcontrol/internal/conf:all-srcs",
"//app/service/live/live_riskcontrol/internal/dao:all-srcs",
"//app/service/live/live_riskcontrol/internal/model:all-srcs",
"//app/service/live/live_riskcontrol/internal/server/http:all-srcs",
"//app/service/live/live_riskcontrol/internal/service:all-srcs",
],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

View File

@@ -0,0 +1,2 @@
### v1.0.0
1. 上线功能xxx

View File

@@ -0,0 +1,6 @@
# Owner
liuzhen
# Author
# Reviewer

View File

@@ -0,0 +1,10 @@
# See the OWNERS docs at https://go.k8s.io/owners
approvers:
- liuzhen
labels:
- live
- service
- service/live/live_riskcontrol
options:
no_parent_owners: true

View File

@@ -0,0 +1,12 @@
# live_riskcontrol-service
## 项目简介
1.
## 编译环境
## 依赖包
## 编译执行

View File

@@ -0,0 +1,56 @@
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_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/service/live/live_riskcontrol/api/grpc/v1",
proto = ":v1_proto",
tags = ["automanaged"],
deps = ["@com_github_gogo_protobuf//gogoproto:go_default_library"],
)
go_library(
name = "go_default_library",
srcs = ["client.go"],
embed = [":v1_go_proto"],
importpath = "go-common/app/service/live/live_riskcontrol/api/grpc/v1",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//library/net/rpc/warden:go_default_library",
"@com_github_gogo_protobuf//gogoproto:go_default_library",
"@com_github_golang_protobuf//proto:go_default_library",
"@org_golang_google_grpc//: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,304 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// source: riskcontrol.proto
package v1
import (
context "context"
fmt "fmt"
_ "github.com/gogo/protobuf/gogoproto"
proto "github.com/golang/protobuf/proto"
grpc "google.golang.org/grpc"
math "math"
)
// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
var _ = fmt.Errorf
var _ = math.Inf
// This is a compile-time assertion to ensure that this generated file
// is compatible with the proto package it is being compiled against.
// A compilation error at this line likely means your copy of the
// proto package needs to be updated.
const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
type GetForbiddenReply_ForbiddenRes int32
const (
GetForbiddenReply_PASS GetForbiddenReply_ForbiddenRes = 0
GetForbiddenReply_FORBIDDEN GetForbiddenReply_ForbiddenRes = 1
GetForbiddenReply_DOUBT GetForbiddenReply_ForbiddenRes = 2
)
var GetForbiddenReply_ForbiddenRes_name = map[int32]string{
0: "PASS",
1: "FORBIDDEN",
2: "DOUBT",
}
var GetForbiddenReply_ForbiddenRes_value = map[string]int32{
"PASS": 0,
"FORBIDDEN": 1,
"DOUBT": 2,
}
func (x GetForbiddenReply_ForbiddenRes) String() string {
return proto.EnumName(GetForbiddenReply_ForbiddenRes_name, int32(x))
}
func (GetForbiddenReply_ForbiddenRes) EnumDescriptor() ([]byte, []int) {
return fileDescriptor_02186d23d36e97ba, []int{1, 0}
}
// GetForbiddenReq
type GetForbiddenReq struct {
Uid int64 `protobuf:"varint,1,opt,name=uid,proto3" json:"uid,omitempty"`
Uri string `protobuf:"bytes,2,opt,name=uri,proto3" json:"uri,omitempty"`
Ip string `protobuf:"bytes,3,opt,name=ip,proto3" json:"ip,omitempty"`
Method string `protobuf:"bytes,4,opt,name=method,proto3" json:"method,omitempty"`
Header map[string]string `protobuf:"bytes,5,rep,name=header,proto3" json:"header,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"`
Body string `protobuf:"bytes,6,opt,name=body,proto3" json:"body,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *GetForbiddenReq) Reset() { *m = GetForbiddenReq{} }
func (m *GetForbiddenReq) String() string { return proto.CompactTextString(m) }
func (*GetForbiddenReq) ProtoMessage() {}
func (*GetForbiddenReq) Descriptor() ([]byte, []int) {
return fileDescriptor_02186d23d36e97ba, []int{0}
}
func (m *GetForbiddenReq) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_GetForbiddenReq.Unmarshal(m, b)
}
func (m *GetForbiddenReq) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_GetForbiddenReq.Marshal(b, m, deterministic)
}
func (m *GetForbiddenReq) XXX_Merge(src proto.Message) {
xxx_messageInfo_GetForbiddenReq.Merge(m, src)
}
func (m *GetForbiddenReq) XXX_Size() int {
return xxx_messageInfo_GetForbiddenReq.Size(m)
}
func (m *GetForbiddenReq) XXX_DiscardUnknown() {
xxx_messageInfo_GetForbiddenReq.DiscardUnknown(m)
}
var xxx_messageInfo_GetForbiddenReq proto.InternalMessageInfo
func (m *GetForbiddenReq) GetUid() int64 {
if m != nil {
return m.Uid
}
return 0
}
func (m *GetForbiddenReq) GetUri() string {
if m != nil {
return m.Uri
}
return ""
}
func (m *GetForbiddenReq) GetIp() string {
if m != nil {
return m.Ip
}
return ""
}
func (m *GetForbiddenReq) GetMethod() string {
if m != nil {
return m.Method
}
return ""
}
func (m *GetForbiddenReq) GetHeader() map[string]string {
if m != nil {
return m.Header
}
return nil
}
func (m *GetForbiddenReq) GetBody() string {
if m != nil {
return m.Body
}
return ""
}
// GetForbiddenReply
type GetForbiddenReply struct {
IsForbidden GetForbiddenReply_ForbiddenRes `protobuf:"varint,1,opt,name=is_forbidden,json=isForbidden,proto3,enum=live.riskcontrol.v1.GetForbiddenReply_ForbiddenRes" json:"is_forbidden,omitempty"`
IsCache bool `protobuf:"varint,2,opt,name=is_cache,json=isCache,proto3" json:"is_cache,omitempty"`
Reason string `protobuf:"bytes,3,opt,name=reason,proto3" json:"reason,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *GetForbiddenReply) Reset() { *m = GetForbiddenReply{} }
func (m *GetForbiddenReply) String() string { return proto.CompactTextString(m) }
func (*GetForbiddenReply) ProtoMessage() {}
func (*GetForbiddenReply) Descriptor() ([]byte, []int) {
return fileDescriptor_02186d23d36e97ba, []int{1}
}
func (m *GetForbiddenReply) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_GetForbiddenReply.Unmarshal(m, b)
}
func (m *GetForbiddenReply) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_GetForbiddenReply.Marshal(b, m, deterministic)
}
func (m *GetForbiddenReply) XXX_Merge(src proto.Message) {
xxx_messageInfo_GetForbiddenReply.Merge(m, src)
}
func (m *GetForbiddenReply) XXX_Size() int {
return xxx_messageInfo_GetForbiddenReply.Size(m)
}
func (m *GetForbiddenReply) XXX_DiscardUnknown() {
xxx_messageInfo_GetForbiddenReply.DiscardUnknown(m)
}
var xxx_messageInfo_GetForbiddenReply proto.InternalMessageInfo
func (m *GetForbiddenReply) GetIsForbidden() GetForbiddenReply_ForbiddenRes {
if m != nil {
return m.IsForbidden
}
return GetForbiddenReply_PASS
}
func (m *GetForbiddenReply) GetIsCache() bool {
if m != nil {
return m.IsCache
}
return false
}
func (m *GetForbiddenReply) GetReason() string {
if m != nil {
return m.Reason
}
return ""
}
func init() {
proto.RegisterEnum("live.riskcontrol.v1.GetForbiddenReply_ForbiddenRes", GetForbiddenReply_ForbiddenRes_name, GetForbiddenReply_ForbiddenRes_value)
proto.RegisterType((*GetForbiddenReq)(nil), "live.riskcontrol.v1.GetForbiddenReq")
proto.RegisterMapType((map[string]string)(nil), "live.riskcontrol.v1.GetForbiddenReq.HeaderEntry")
proto.RegisterType((*GetForbiddenReply)(nil), "live.riskcontrol.v1.GetForbiddenReply")
}
func init() { proto.RegisterFile("riskcontrol.proto", fileDescriptor_02186d23d36e97ba) }
var fileDescriptor_02186d23d36e97ba = []byte{
// 482 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x93, 0xcf, 0x6e, 0xd3, 0x40,
0x10, 0xc6, 0xb1, 0x9d, 0x9a, 0x64, 0x12, 0xc0, 0x5d, 0x38, 0x58, 0x91, 0xc0, 0xee, 0xaa, 0x40,
0x2e, 0xb8, 0x24, 0xe5, 0x50, 0x22, 0x71, 0xc0, 0xa4, 0x85, 0x5e, 0x28, 0x72, 0xe1, 0x82, 0x90,
0x2a, 0x3b, 0xde, 0xc4, 0xab, 0x38, 0x59, 0x77, 0xfd, 0x47, 0xf2, 0x83, 0x72, 0xf5, 0x03, 0xe4,
0x98, 0x07, 0x40, 0x28, 0xbb, 0xa1, 0x72, 0x50, 0x2a, 0xe5, 0xe4, 0x99, 0xcf, 0xf3, 0x9b, 0x99,
0xfd, 0xd6, 0x86, 0x43, 0x4e, 0xd3, 0xd9, 0x98, 0x2d, 0x32, 0xce, 0x62, 0x27, 0xe1, 0x2c, 0x63,
0xe8, 0x69, 0x4c, 0x0b, 0xe2, 0xd4, 0xf5, 0xa2, 0xdf, 0x7d, 0x33, 0xa5, 0x59, 0x94, 0x07, 0xce,
0x98, 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 0x00,
}
// Reference imports to suppress errors if they are not otherwise used.
var _ context.Context
var _ grpc.ClientConn
// This is a compile-time assertion to ensure that this generated file
// is compatible with the grpc package it is being compiled against.
const _ = grpc.SupportPackageIsVersion4
// IsForbiddenClient is the client API for IsForbidden service.
//
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream.
type IsForbiddenClient interface {
GetForbidden(ctx context.Context, in *GetForbiddenReq, opts ...grpc.CallOption) (*GetForbiddenReply, error)
}
type isForbiddenClient struct {
cc *grpc.ClientConn
}
func NewIsForbiddenClient(cc *grpc.ClientConn) IsForbiddenClient {
return &isForbiddenClient{cc}
}
func (c *isForbiddenClient) GetForbidden(ctx context.Context, in *GetForbiddenReq, opts ...grpc.CallOption) (*GetForbiddenReply, error) {
out := new(GetForbiddenReply)
err := c.cc.Invoke(ctx, "/live.riskcontrol.v1.IsForbidden/GetForbidden", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// IsForbiddenServer is the server API for IsForbidden service.
type IsForbiddenServer interface {
GetForbidden(context.Context, *GetForbiddenReq) (*GetForbiddenReply, error)
}
func RegisterIsForbiddenServer(s *grpc.Server, srv IsForbiddenServer) {
s.RegisterService(&_IsForbidden_serviceDesc, srv)
}
func _IsForbidden_GetForbidden_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(GetForbiddenReq)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(IsForbiddenServer).GetForbidden(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/live.riskcontrol.v1.IsForbidden/GetForbidden",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(IsForbiddenServer).GetForbidden(ctx, req.(*GetForbiddenReq))
}
return interceptor(ctx, in, info, handler)
}
var _IsForbidden_serviceDesc = grpc.ServiceDesc{
ServiceName: "live.riskcontrol.v1.IsForbidden",
HandlerType: (*IsForbiddenServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "GetForbidden",
Handler: _IsForbidden_GetForbidden_Handler,
},
},
Streams: []grpc.StreamDesc{},
Metadata: "riskcontrol.proto",
}

View File

@@ -0,0 +1,31 @@
syntax = "proto3";
package live.riskcontrol.v1;
option go_package = "v1";
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
// GetForbiddenReq
message GetForbiddenReq {
int64 uid = 1 [(gogoproto.moretags) = 'form:"uid" validate:"required"'];
string uri = 2 [(gogoproto.moretags) = 'form:"uri" validate:"required"'];
string ip = 3 [(gogoproto.moretags) = 'form:"ip" validate:"required"'];
string method = 4 [(gogoproto.moretags) = 'form:"method" validate:"required"'];
map<string,string> header = 5 [(gogoproto.moretags) = 'form:"header" validate:"required"'];
string body = 6 [(gogoproto.moretags) = 'form:"body" validate:"required"'];
}
// GetForbiddenReply
message GetForbiddenReply {
enum ForbiddenRes {
PASS = 0;
FORBIDDEN = 1;
DOUBT = 2;
}
ForbiddenRes is_forbidden = 1 [(gogoproto.jsontag) = "is_forbidden"];
bool is_cache = 2 [(gogoproto.jsontag) = "is_cache"];
string reason = 3 [(gogoproto.jsontag) = "reason"];
}
service IsForbidden {
rpc GetForbidden(GetForbiddenReq) returns (GetForbiddenReply);
}

View File

@@ -0,0 +1,23 @@
package v1
import (
"context"
"go-common/library/net/rpc/warden"
"google.golang.org/grpc"
)
//AppID 直播风控服务discoverID
const AppID = "live.riskcontrol"
//NewClient 直播风控服务client创建
func NewClient(cfg *warden.ClientConfig, opts ...grpc.DialOption) (IsForbiddenClient, error) {
client := warden.NewClient(cfg, opts...)
conn, err := client.Dial(context.Background(), "discovery://detault/"+AppID)
if err != nil {
return nil, err
}
return NewIsForbiddenClient(conn), nil
}

View File

@@ -0,0 +1,44 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_binary",
"go_library",
)
go_binary(
name = "cmd",
embed = [":go_default_library"],
tags = ["automanaged"],
)
go_library(
name = "go_default_library",
srcs = ["main.go"],
data = ["test.toml"],
importpath = "go-common/app/service/live/live_riskcontrol/cmd",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/service/live/live_riskcontrol/internal/conf:go_default_library",
"//app/service/live/live_riskcontrol/internal/server/http:go_default_library",
"//app/service/live/live_riskcontrol/internal/service:go_default_library",
"//library/ecode/tip:go_default_library",
"//library/log:go_default_library",
"//library/net/trace: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,47 @@
package main
import (
"flag"
"os"
"os/signal"
"syscall"
"time"
"go-common/app/service/live/live_riskcontrol/internal/conf"
"go-common/app/service/live/live_riskcontrol/internal/server/http"
"go-common/app/service/live/live_riskcontrol/internal/service"
ecode "go-common/library/ecode/tip"
"go-common/library/log"
"go-common/library/net/trace"
)
func main() {
flag.Parse()
if err := conf.Init(); err != nil {
panic(err)
}
log.Init(conf.Conf.Log)
defer log.Close()
log.Info("live_riskcontrol-service start")
trace.Init(conf.Conf.Tracer)
defer trace.Close()
ecode.Init(conf.Conf.Ecode)
svc := service.New(conf.Conf)
http.Init(conf.Conf, svc)
c := make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
for {
s := <-c
log.Info("get a signal %s", s.String())
switch s {
case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT:
svc.Close()
log.Info("live_riskcontrol-service exit")
time.Sleep(time.Second)
return
case syscall.SIGHUP:
default:
return
}
}
}

View File

@@ -0,0 +1,35 @@
[mysql]
addr = "127.0.0.1:3306"
dsn = "test:test@tcp(127.0.0.1:3306)/test?timeout=200ms&readTimeout=200ms&writeTimeout=200ms&parseTime=true&loc=Local&charset=utf8,utf8mb4"
readDSN = ["test:test@tcp(127.0.0.2:3306)/test? timeout=200ms&readTimeout=200ms&writeTimeout=200ms&parseTime=true&loc=Local&charset=utf8,utf8mb4","test:test@tcp(127.0.0.3:3306)/test?timeout=200ms&readTimeout=200ms&writeTimeout=200ms&parseTime=true&loc=Local&charset=utf8,utf8mb4"]
active = 20
idle = 10
idleTimeout ="4h"
queryTimeout = "100ms"
execTimeout = "100ms"
tranTimeout = "200ms"
[redis]
name = "live_riskcontrol-service"
proto = "tcp"
addr = ""
idle = 10
active = 10
dialTimeout = "1s"
readTimeout = "1s"
writeTimeout = "1s"
idleTimeout = "10s"
expire = "1m"
[memcache]
name = "live_riskcontrol-service"
proto = "tcp"
addr = ""
active = 50
idle = 10
dialTimeout = "1s"
readTimeout = "1s"
writeTimeout = "1s"
idleTimeout = "10s"
expire = "24h"

View File

@@ -0,0 +1,40 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
)
go_library(
name = "go_default_library",
srcs = ["conf.go"],
importpath = "go-common/app/service/live/live_riskcontrol/internal/conf",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//library/cache/memcache:go_default_library",
"//library/cache/redis:go_default_library",
"//library/conf:go_default_library",
"//library/database/sql:go_default_library",
"//library/ecode/tip:go_default_library",
"//library/log:go_default_library",
"//library/net/http/blademaster:go_default_library",
"//library/net/http/blademaster/middleware/verify:go_default_library",
"//library/net/trace:go_default_library",
"//vendor/github.com/BurntSushi/toml: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,88 @@
package conf
import (
"errors"
"flag"
"go-common/library/cache/memcache"
"go-common/library/cache/redis"
"go-common/library/conf"
"go-common/library/database/sql"
ecode "go-common/library/ecode/tip"
"go-common/library/log"
bm "go-common/library/net/http/blademaster"
"go-common/library/net/http/blademaster/middleware/verify"
"go-common/library/net/trace"
"github.com/BurntSushi/toml"
)
var (
confPath string
client *conf.Client
// Conf config
Conf = &Config{}
)
// Config .
type Config struct {
Log *log.Config
BM *bm.ServerConfig
Verify *verify.Config
Tracer *trace.Config
Redis *redis.Config
Memcache *memcache.Config
MySQL *sql.Config
Ecode *ecode.Config
}
func init() {
flag.StringVar(&confPath, "conf", "", "default config path")
}
// Init init conf
func Init() error {
if confPath != "" {
return local()
}
return remote()
}
func local() (err error) {
_, err = toml.DecodeFile(confPath, &Conf)
return
}
func remote() (err error) {
if client, err = conf.New(); err != nil {
return
}
if err = load(); err != nil {
return
}
go func() {
for range client.Event() {
log.Info("config reload")
if load() != nil {
log.Error("config reload error (%v)", err)
}
}
}()
return
}
func load() (err error) {
var (
s string
ok bool
tmpConf *Config
)
if s, ok = client.Toml2(); !ok {
return errors.New("load config center error")
}
if _, err = toml.Decode(s, &tmpConf); err != nil {
return errors.New("could not decode config")
}
*Conf = *tmpConf
return
}

View File

@@ -0,0 +1,34 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
)
go_library(
name = "go_default_library",
srcs = ["dao.go"],
importpath = "go-common/app/service/live/live_riskcontrol/internal/dao",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/service/live/live_riskcontrol/internal/conf:go_default_library",
"//library/cache/memcache:go_default_library",
"//library/cache/redis:go_default_library",
"//library/database/sql: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,42 @@
package dao
import (
"context"
"go-common/app/service/live/live_riskcontrol/internal/conf"
"go-common/library/cache/memcache"
"go-common/library/cache/redis"
xsql "go-common/library/database/sql"
)
// Dao dao
type Dao struct {
c *conf.Config
mc *memcache.Pool
redis *redis.Pool
db *xsql.DB
}
// New init mysql db
func New(c *conf.Config) (dao *Dao) {
dao = &Dao{
c: c,
mc: memcache.NewPool(c.Memcache),
redis: redis.NewPool(c.Redis),
db: xsql.NewMySQL(c.MySQL),
}
return
}
// Close close the resource.
func (d *Dao) Close() {
d.mc.Close()
d.redis.Close()
d.db.Close()
}
// Ping dao ping
func (d *Dao) Ping(ctx context.Context) error {
// TODO: add mc,redis... if you use
return d.db.Ping(ctx)
}

View File

@@ -0,0 +1,28 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
)
go_library(
name = "go_default_library",
srcs = ["model.go"],
importpath = "go-common/app/service/live/live_riskcontrol/internal/model",
tags = ["automanaged"],
visibility = ["//visibility:public"],
)
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 @@
package model

View File

@@ -0,0 +1,35 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
)
go_library(
name = "go_default_library",
srcs = ["http.go"],
importpath = "go-common/app/service/live/live_riskcontrol/internal/server/http",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/service/live/live_riskcontrol/internal/conf:go_default_library",
"//app/service/live/live_riskcontrol/internal/service:go_default_library",
"//library/log:go_default_library",
"//library/net/http/blademaster:go_default_library",
"//library/net/http/blademaster/middleware/verify: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,53 @@
package http
import (
"net/http"
"go-common/app/service/live/live_riskcontrol/internal/conf"
"go-common/app/service/live/live_riskcontrol/internal/service"
"go-common/library/log"
bm "go-common/library/net/http/blademaster"
"go-common/library/net/http/blademaster/middleware/verify"
)
var (
vfy *verify.Verify
svc *service.Service
)
// Init init
func Init(c *conf.Config, s *service.Service) {
svc = s
vfy = verify.New(c.Verify)
engine := bm.DefaultServer(c.BM)
route(engine)
if err := engine.Start(); err != nil {
log.Error("bm Start error(%v)", err)
panic(err)
}
}
func route(e *bm.Engine) {
e.Ping(ping)
e.Register(register)
g := e.Group("/x/live_riskcontrol")
{
g.GET("/start", vfy.Verify, howToStart)
}
}
func ping(ctx *bm.Context) {
if err := svc.Ping(ctx); err != nil {
log.Error("ping error(%v)", err)
ctx.AbortWithStatus(http.StatusServiceUnavailable)
}
}
func register(c *bm.Context) {
c.JSON(map[string]interface{}{}, nil)
}
// example for http request handler
func howToStart(c *bm.Context) {
c.String(0, "Golang 大法好 !!!")
}

View File

@@ -0,0 +1,32 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
)
go_library(
name = "go_default_library",
srcs = ["service.go"],
importpath = "go-common/app/service/live/live_riskcontrol/internal/service",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/service/live/live_riskcontrol/internal/conf:go_default_library",
"//app/service/live/live_riskcontrol/internal/dao: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,33 @@
package service
import (
"context"
"go-common/app/service/live/live_riskcontrol/internal/conf"
"go-common/app/service/live/live_riskcontrol/internal/dao"
)
// Service struct
type Service struct {
c *conf.Config
dao *dao.Dao
}
// New init
func New(c *conf.Config) (s *Service) {
s = &Service{
c: c,
dao: dao.New(c),
}
return s
}
// Ping Service
func (s *Service) Ping(ctx context.Context) (err error) {
return s.dao.Ping(ctx)
}
// Close Service
func (s *Service) Close() {
s.dao.Close()
}