Skip to content

Commit

Permalink
Add upload server.
Browse files Browse the repository at this point in the history
  • Loading branch information
wubenqi committed Mar 10, 2018
1 parent bb3d4ef commit f5d9c3a
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 4 deletions.
68 changes: 64 additions & 4 deletions biz_server/upload/upload.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, https://github.com/nebulaim
* Copyright (c) 2018, https://github.com/nebulaim
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -17,8 +17,68 @@

package main

import "github.com/nebulaim/telegramd/biz_server/upload/rpc"
import (
"flag"
"github.com/golang/glog"

func main() {
rpc.DoMainServer()
upload "github.com/nebulaim/telegramd/biz_server/upload/rpc"
"github.com/nebulaim/telegramd/mtproto"
"github.com/nebulaim/telegramd/base/redis_client"
"github.com/nebulaim/telegramd/base/mysql_client"
"github.com/BurntSushi/toml"
"fmt"
"github.com/nebulaim/telegramd/biz_model/dal/dao"
"github.com/nebulaim/telegramd/grpc_util"
"github.com/nebulaim/telegramd/grpc_util/service_discovery"
"google.golang.org/grpc"
)

func init() {
flag.Set("alsologtostderr", "true")
flag.Set("log_dir", "false")
}

type RpcServerConfig struct {
Addr string
}

//type RpcClientConfig struct {
// ServiceName string
// Addr string
//}

type uploadServerConfig struct{
Server *RpcServerConfig
Discovery service_discovery.ServiceDiscoveryServerConfig

// RpcClient *RpcClientConfig
Mysql []mysql_client.MySQLConfig
Redis []redis_client.RedisConfig
}

// 整合各服务,方便开发调试
func main() {
flag.Parse()

config := &uploadServerConfig{}
if _, err := toml.DecodeFile("./upload.toml", config); err != nil {
fmt.Errorf("%s\n", err)
return
}

glog.Info(config)

// 初始化mysql_client、redis_client
redis_client.InstallRedisClientManager(config.Redis)
mysql_client.InstallMysqlClientManager(config.Mysql)

// 初始化redis_dao、mysql_dao
dao.InstallMysqlDAOManager(mysql_client.GetMysqlClientManager())
dao.InstallRedisDAOManager(redis_client.GetRedisClientManager())

// Start server
grpcServer := grpc_util.NewRpcServer(config.Server.Addr, &config.Discovery)
grpcServer.Serve(func(s *grpc.Server) {
mtproto.RegisterRPCUploadServer(s, &upload.UploadServiceImpl{})
})
}
41 changes: 41 additions & 0 deletions biz_server/upload/upload.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# biz_server.toml

ver = "0.0.1"
#logPath = "/tmp/biz_server.log"

[server]
addr = "0.0.0.0:10004"

[discovery]
serviceName = "upload"
nodeID = "node1"
rPCAddr = "127.0.0.1:10001"
etcdAddrs = ["http://127.0.0.1:2379"]
interval = "2s"
tTL = "10s"

[[redis]]
name = "cache"
addr = "127.0.0.1:6379"
idle = 100
active = 100
dialTimeout = "1s"
readTimeout = "1s"
writeTimeout = "1s"
idleTimeout = "10s"
dbNum = "0"
password = ""

[[mysql]]
name = "immaster"
dsn = "root:@/nebulaim?charset=utf8mb4"
#root:1@tcp(127.0.0.1:3306)/nebulaim?timeout=5s&readTimeout=5s&writeTimeout=5s&parseTime=true&loc=Local&charset=utf8,utf8mb4"
active = 5
idle = 2

[[mysql]]
name = "imslave"
dsn = "root:@/nebulaim?charset=utf8mb4"
# root:1@tcp(127.0.0.1:3306)/nebulaim?timeout=5s&readTimeout=5s&writeTimeout=5s&parseTime=true&loc=Local&charset=utf8,utf8mb4"
active = 5
idle = 2

0 comments on commit f5d9c3a

Please sign in to comment.