This commit is contained in:
crusader 2018-04-10 14:21:48 +09:00
parent 3a7af25014
commit b55a07327e
4 changed files with 126 additions and 33 deletions

41
external/external.go vendored
View File

@ -1,9 +1,44 @@
package external
func InitPackage() {
import (
occe "git.loafle.net/overflow/commons-go/config/external"
"git.loafle.net/overflow/gateway/external/grpc"
"git.loafle.net/overflow/gateway/external/kafka"
"git.loafle.net/overflow/gateway/external/redis"
)
func InitPackage(config *occe.ExternalConfig) {
if nil == config {
return
}
grpc.InitPackage(config.GRPC)
redis.InitPackage(config.Redis)
kafka.InitPackage(config.Kafka)
}
func DestroyPackage() {
func StartPackage(config *occe.ExternalConfig) {
if nil == config {
return
}
grpc.StartPackage(config.GRPC)
redis.StartPackage(config.Redis)
kafka.StartPackage(config.Kafka)
}
func StopPackage(config *occe.ExternalConfig) {
if nil == config {
return
}
grpc.StopPackage(config.GRPC)
redis.StopPackage(config.Redis)
kafka.StopPackage(config.Kafka)
}
func DestroyPackage(config *occe.ExternalConfig) {
if nil == config {
return
}
grpc.DestroyPackage(config.GRPC)
redis.DestroyPackage(config.Redis)
kafka.DestroyPackage(config.Kafka)
}

24
external/grpc/grpc.go vendored
View File

@ -8,12 +8,16 @@ import (
"git.loafle.net/commons/logging-go"
oci "git.loafle.net/overflow/central_api/golang"
occeg "git.loafle.net/overflow/commons-go/config/external/grpc"
"google.golang.org/grpc"
)
var grpcClient oci.OverflowApiServerClient
func InitPackage() {
func InitPackage(config *occeg.GRPConfig) {
if nil == config {
return
}
go func() {
conn, err := grpc.Dial("192.168.1.50:50006", grpc.WithInsecure())
if nil != err {
@ -21,10 +25,26 @@ func InitPackage() {
}
grpcClient = oci.NewOverflowApiServerClient(conn)
}()
}
func StartPackage(config *occeg.GRPConfig) {
if nil == config {
return
}
}
func DestroyPackage() {
func StopPackage(config *occeg.GRPConfig) {
if nil == config {
return
}
}
func DestroyPackage(config *occeg.GRPConfig) {
if nil == config {
return
}
}

View File

@ -5,6 +5,7 @@ import (
"fmt"
"git.loafle.net/commons/logging-go"
occek "git.loafle.net/overflow/commons-go/config/external/kafka"
"github.com/segmentio/kafka-go"
)
@ -12,22 +13,38 @@ var (
kafkaWriter *kafka.Writer
)
func InitPackage() {
go func() {
func InitPackage(config *occek.KafkaConfig) {
kafkaWriter = kafka.NewWriter(kafka.WriterConfig{
Brokers: []string{"192.168.1.50:9092"},
Topic: "overflow-metric-topic",
Balancer: &kafka.LeastBytes{},
})
}()
}
func StartPackage(config *occek.KafkaConfig) {
if nil == config {
return
}
}
func StopPackage(config *occek.KafkaConfig) {
if nil == config {
return
}
}
func DestroyPackage(config *occek.KafkaConfig) {
if nil == config {
return
}
func DestroyPackage() {
go func() {
if err := kafkaWriter.Close(); nil != err {
logging.Logger().Errorf("%v", err)
}
}()
}
func Write(key []byte, value []byte) error {

View File

@ -1,13 +1,17 @@
package redis
import (
occer "git.loafle.net/overflow/commons-go/config/external/redis"
"github.com/gomodule/redigo/redis"
)
var Pool *redis.Pool
func InitPackage() {
go func() {
func InitPackage(config *occer.RedisConfig) {
if nil == config {
return
}
Pool = &redis.Pool{
MaxIdle: 1,
MaxActive: 3,
@ -18,9 +22,26 @@ func InitPackage() {
return redis.Dial("tcp", "192.168.1.50:6379")
},
}
}()
}
func DestroyPackage() {
func StartPackage(config *occer.RedisConfig) {
if nil == config {
return
}
}
func StopPackage(config *occer.RedisConfig) {
if nil == config {
return
}
}
func DestroyPackage(config *occer.RedisConfig) {
if nil == config {
return
}
Pool.Close()
}