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,27 @@
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/infra/databus/model",
tags = ["automanaged"],
)
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,62 @@
package model
import (
"errors"
)
const (
bit1 = int8(1)
bit2 = int8(1) << 1
// PubOnly pub only
PubOnly = bit2 | int8(0)
// SubOnly sub only
SubOnly = int8(0) | bit1
// PubSub pub and sub
PubSub = bit2 | bit1
)
var (
errGroup = errors.New("error group")
errTopic = errors.New("error topic")
errKey = errors.New("error key")
errSecret = errors.New("error secret")
)
// Auth databus auth info accordance with table:bilibili_databus_v2.auth
type Auth struct {
Group string
Topic string
Operation int8
Key string
Secret string
Batch int64
Cluster string
}
// CanPub judge producer auth
func (a *Auth) CanPub() bool {
return a.Operation&bit2 == bit2
}
// CanSub judge consumer auth
func (a *Auth) CanSub() bool {
return a.Operation&bit1 == bit1
}
// Auth judge auth
func (a *Auth) Auth(group, topic, key, secret string) error {
if a.Group != group {
return errGroup
}
if a.Topic != topic {
return errTopic
}
if a.Key != key {
return errKey
}
if a.Secret != secret {
return errSecret
}
return nil
}