Skip to content
This repository has been archived by the owner on May 11, 2019. It is now read-only.

Commit

Permalink
first time SIT pass
Browse files Browse the repository at this point in the history
SIT ( System intergraction Testing )  pass
  • Loading branch information
tsingson committed Mar 30, 2019
1 parent f0a738c commit 93d18e2
Show file tree
Hide file tree
Showing 12 changed files with 138 additions and 98 deletions.
14 changes: 7 additions & 7 deletions cmd/nats/comet/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ func main() {
}

cfg.Env = &conf.Env{
Region: "test",
Zone: "test",
DeployEnv: "test",
Host: "test_server",
Region: "china",
Zone: "gd",
DeployEnv: "dev",
Host: "comet",
}

rand.Seed(time.Now().UTC().UnixNano())
Expand All @@ -64,9 +64,9 @@ func main() {
resolver.Register(dis)
// new comet server
srv := comet.NewServer(cfg)
// if err := comet.InitWhitelist(cfg.Whitelist); err != nil {
// panic(err)
// }
if err := comet.InitWhitelist(cfg.Whitelist); err != nil {
panic(err)
}
if err := comet.InitTCP(srv, cfg.TCP.Bind, runtime.NumCPU()); err != nil {
panic(err)
}
Expand Down
8 changes: 4 additions & 4 deletions cmd/nats/job/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ func main() {

cfg = conf.Default()
env := &conf.Env{
Region: "test",
Zone: "test",
DeployEnv: "test",
Host: "localhost",
Region: "china",
Zone: "gd",
DeployEnv: "dev",
Host: "job",
}
cfg.Env = env

Expand Down
48 changes: 26 additions & 22 deletions cmd/nats/logic/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package main

import (
"context"
"flag"
"net"
"os"
"os/signal"
"strconv"
"syscall"

"github.com/sanity-io/litter"
"github.com/tsingson/discovery/naming"
resolver "github.com/tsingson/discovery/naming/grpc"
"github.com/tsingson/fastx/utils"
Expand All @@ -27,37 +28,40 @@ const (
appid = "goim.logic"
)

var cfg *conf.NatsConfig
var cfg *conf.LogicConfig

func main() {

path, _ := utils.GetCurrentExecDir()
confPath := path + "/logic-config.toml"

flag.Parse()
var err error
cfg, err = conf.Init(confPath)
cfg, err = conf.LoadToml(confPath)

if err != nil {
panic(err)
}

env := &conf.Env{
Region: "test",
Zone: "test",
DeployEnv: "test",
Host: "localhost",
litter.Dump( cfg )

{
// env := &conf.Env{
// Region: "china",
// Zone: "gd",
// DeployEnv: "sz",
// Host: "logic",
// }
// cfg.Env = env
}
cfg.Env = env

// log.Infof("goim-logic [version: %s env: %+v] start", ver, cfg.Env)
// grpc register naming
dis := naming.New(cfg.Discovery)
resolver.Register(dis)
var dis *naming.Discovery

{
log.Infof("goim-logic [version: %s env: %+v] start", ver, cfg.Env)
// grpc register naming
dis = naming.New(cfg.Discovery)
resolver.Register(dis)
}

// grpc register naming
// dis := naming.New(cfg.Discovery)
// resolver.Register(dis)
// logic
srv := logic.New(cfg)
httpSrv := http.New(cfg.HTTPServer, srv)
Expand Down Expand Up @@ -87,11 +91,11 @@ func main() {
}
}

func register(dis *naming.Discovery, srv *logic.NatsLogic) context.CancelFunc {
func register(dis *naming.Discovery, srv *logic.Logic) context.CancelFunc {
env := cfg.Env
addr := "10.0.0.11" // ip.InternalIP()
// _, port, _ := net.SplitHostPort(cfg.RPCServer.Addr)
port := "3119"
addr := "127.0.0.1" // ip.InternalIP()
_, port, _ := net.SplitHostPort(cfg.RPCServer.Addr)
// port := "3119"
ins := &naming.Instance{
Region: env.Region,
Zone: env.Zone,
Expand Down
6 changes: 3 additions & 3 deletions examples/websocket/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ <h2>status:</h2>
<span id="status"></span>
<h2>push</h2>
<div>
<p>curl -d 'mid message' http://127.0.0.1:3101/goim/push/mids?operation=1000&mids=123</p>
<p>curl -d 'room message' http://127.0.0.1:3101/goim/push/room?operation=1000&type=live&room=1000</p>
<p>curl -d 'broadcast message' http://127.0.0.1:3101/goim/push/all?operation=1000</p>
<p>curl -d 'mid message' http://127.0.0.1:3111/goim/push/mids?operation=1000&mids=123</p>
<p>curl -d 'room message' http://127.0.0.1:3111/goim/push/room?operation=1000&type=live&room=1000</p>
<p>curl -d 'broadcast message' http://127.0.0.1:3111/goim/push/all?operation=1000</p>
</div>
<h2>message:</h2>
<div id="box"></div>
Expand Down
2 changes: 1 addition & 1 deletion examples/websocket/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ import (

func main() {
// Simple static webserver:
log.Fatal(http.ListenAndServe(":1998", http.FileServer(http.Dir("./"))))
log.Fatal(http.ListenAndServe(":1999", http.FileServer(http.Dir("./"))))
}
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ require (
github.com/Workiva/go-datastructures v1.0.50 // indirect
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da // indirect
github.com/boltdb/bolt v1.3.1 // indirect
github.com/bsm/sarama-cluster v2.1.15+incompatible
github.com/dustin/go-humanize v1.0.0 // indirect
github.com/gin-gonic/gin v1.3.0
github.com/gogo/protobuf v1.2.1
github.com/golang/protobuf v1.3.1
github.com/gomodule/redigo v2.0.0+incompatible
github.com/google/uuid v1.1.1
github.com/hako/durafmt v0.0.0-20180520121703-7b7ae1e72ead // indirect
github.com/hashicorp/go-immutable-radix v1.0.0 // indirect
github.com/hashicorp/go-msgpack v0.5.3 // indirect
Expand All @@ -27,6 +29,7 @@ require (
github.com/nats-io/nuid v1.0.0 // indirect
github.com/nsip/gommap v0.0.0-20181229045655-f7881c3a959f // indirect
github.com/pascaldekloe/goe v0.1.0 // indirect
github.com/sanity-io/litter v1.1.0
github.com/sirupsen/logrus v1.4.0 // indirect
github.com/stretchr/testify v1.3.0
github.com/tsingson/discovery v0.1.0
Expand Down
12 changes: 12 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT
github.com/AndreasBriese/bbloom v0.0.0-20180913140656-343706a395b7/go.mod h1:bOvUY6CB00SOBii9/FifXqc0awNKxLFCL/+pkDPuyl8=
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/DataDog/zstd v1.3.5 h1:DtpNbljikUepEPD16hD4LvIcmhnhdLTiW/5pHgbmp14=
github.com/DataDog/zstd v1.3.5/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo=
github.com/NetWatcher/service v0.0.0-20170526123706-12236803cddf h1:TKizf/caqRAmi8ctrzoPTjZNFV8RnlY8aAve8Qw8nu4=
github.com/NetWatcher/service v0.0.0-20170526123706-12236803cddf/go.mod h1:/qXMWgh5hccv5xCa/Fq6UF0msHhpTOV7gh3GYN47rBo=
github.com/Shopify/sarama v1.21.0 h1:0GKs+e8mn1RRUzfg9oUXv3v7ZieQLmOZF/bfnmmGhM8=
github.com/Shopify/sarama v1.21.0/go.mod h1:yuqtN/pe8cXRWG5zPaO7hCfNJp5MwmkoJEoLjkm5tCQ=
github.com/Shopify/toxiproxy v2.1.4+incompatible h1:TKdv8HiTLgE5wdJuEML90aBgNWsokNbMijUGhmcoBJc=
github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI=
github.com/Workiva/go-datastructures v1.0.50 h1:slDmfW6KCHcC7U+LP3DDBbm4fqTwZGn1beOFPfGaLvo=
github.com/Workiva/go-datastructures v1.0.50/go.mod h1:Z+F2Rca0qCsVYDS8z7bAGm8f3UkzuWYS/oBZz5a7VVA=
Expand All @@ -16,6 +19,8 @@ github.com/boltdb/bolt v1.3.1 h1:JQmyP4ZBrce+ZQu0dY660FMfatumYDLun9hBCUVIkF4=
github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps=
github.com/bsm/go-guid v1.0.0 h1:E3M8Rmd8WEVQ3w7pFXemZaKApnHGnSXuiu9ALE1xnj8=
github.com/bsm/go-guid v1.0.0/go.mod h1:N5CP3axb8BxDAfWR2mlBNASD66YjIlI3LXqoaRSGGE4=
github.com/bsm/sarama-cluster v2.1.15+incompatible h1:RkV6WiNRnqEEbp81druK8zYhmnIgdOjqSVi0+9Cnl2A=
github.com/bsm/sarama-cluster v2.1.15+incompatible/go.mod h1:r7ao+4tTNXvWm+VRpRJchr2kQhqxgmAp2iEX5W96gMM=
github.com/btcsuite/btcutil v0.0.0-20190207003914-4c204d697803 h1:j3AgPKKZtZStM2nyhrDSLSYgT7YHrZKdSkq1OYeLjvM=
github.com/btcsuite/btcutil v0.0.0-20190207003914-4c204d697803/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
Expand All @@ -27,8 +32,11 @@ github.com/dgraph-io/badger v1.5.4/go.mod h1:VZxzAIRPHRVNRKRo6AXrX9BJegn6il06VMT
github.com/dgryski/go-farm v0.0.0-20190104051053-3adb47b1fb0f/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw=
github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo=
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/eapache/go-resiliency v1.1.0 h1:1NtRmCAqadE2FN4ZcN6g90TP3uk8cg9rn9eNK2197aU=
github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs=
github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21 h1:YEetp8/yCZMuEPMUDHG0CW/brkkEp8mzqk2+ODEitlw=
github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU=
github.com/eapache/queue v1.1.0 h1:YOEu7KNc61ntiQlcEeUIoDTJ2o8mQznoNvUhiigpIqc=
github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I=
github.com/elazarl/goproxy v0.0.0-20181111060418-2ce16c963a8a/go.mod h1:/Zj4wYkgs4iZTTu3o/KG3Itv/qCCa8VVMlb3i9OVuzc=
github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M=
Expand All @@ -51,6 +59,7 @@ github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfb
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.1 h1:YF8+flBXS5eO826T4nzqPrxfhQThhXl0YzfuUPu4SBg=
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db h1:woRePGFeVFfLKN/pOkfl+p/TAqKOfFu+7KPlMVpok/w=
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/gomodule/redigo v2.0.0+incompatible h1:K/R+8tc58AaqLkqG2Ol3Qk+DR/TlNuhuh457pBFPtt0=
github.com/gomodule/redigo v2.0.0+incompatible/go.mod h1:B4C85qUVwatsJoIUNIfCRsp7qO0iAmpGFZ4EELWSbC4=
Expand Down Expand Up @@ -140,15 +149,18 @@ github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1Cpa
github.com/parnurzeal/gorequest v0.2.15/go.mod h1:3Kh2QUMJoqw3icWAecsyzkpY7UzRfDhbRdTjtNwNiUE=
github.com/pascaldekloe/goe v0.1.0 h1:cBOtyMzM9HTpWjXfbbunk26uA6nG3a8n06Wieeh0MwY=
github.com/pascaldekloe/goe v0.1.0/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
github.com/pierrec/lz4 v2.0.5+incompatible h1:2xWsjqPFWcplujydGg4WmhC/6fZqK42wMM8aXeqhl0I=
github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a h1:9ZKAASQSHhDYGoxY8uLVpewe1GDZ2vu2Tr/vTdVAkFQ=
github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
github.com/rs/zerolog v1.12.0/go.mod h1:YbFCdg8HfsridGWAh22vktObvhZbQsZXe4/zB0OKkWU=
github.com/rs/zerolog v1.13.0 h1:hSNcYHyxDWycfePW7pUI8swuFkcSMPKh3E63Pokg1Hk=
github.com/rs/zerolog v1.13.0/go.mod h1:YbFCdg8HfsridGWAh22vktObvhZbQsZXe4/zB0OKkWU=
github.com/sanity-io/litter v1.1.0 h1:BllcKWa3VbZmOZbDCoszYLk7zCsKHz5Beossi8SUcTc=
github.com/sanity-io/litter v1.1.0/go.mod h1:CJ0VCw2q4qKU7LaQr3n7UOSHzgEMgcGco7N/SkZQPjw=
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
Expand Down
17 changes: 8 additions & 9 deletions internal/nats/comet/conf/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ func Init(path string) (cfg *Config, err error) {
_, err = toml.DecodeFile(confPath, &cfg)
}
Conf = cfg

return
}

Expand All @@ -152,20 +151,20 @@ func Default() *Config {
return &Config{
Debug: true,
Env: &Env{
Region: "test",
Zone: "test",
DeployEnv: "test",
Host: "test_server",
Region: "china",
Zone: "gd",
DeployEnv: "dev",
Host: "comet",
Weight: 100,
Addrs: []string{"127.0.0.1:3101"},
Offline: false,
},
Discovery: &naming.Config{
Nodes: []string{"127.0.0.1:7171"},
Region: "test",
Zone: "test",
Env: "test",
Host: "test_server",
Region: "china",
Zone: "gd",
Env: "dev",
Host: "discovery",
},
RPCClient: &RPCClient{
Dial: xtime.Duration(time.Second),
Expand Down
6 changes: 3 additions & 3 deletions internal/nats/dao/nats.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (

// NatsDao dao for nats
type Dao struct {
c *conf.NatsConfig
c *conf.LogicConfig
natsClient *nats.Conn
liftClient liftbridge.Client
redis *redis.Pool
Expand All @@ -28,7 +28,7 @@ type Dao struct {

type NatsDao = Dao

// NatsConfig configuration for nats / liftbridge queue
// LogicConfig configuration for nats / liftbridge queue
type Config struct {
Channel string
ChannelID string
Expand All @@ -40,7 +40,7 @@ type Config struct {
type NatsConfig = Config

// New new a dao and return.
func New(c *conf.NatsConfig) *Dao {
func New(c *conf.LogicConfig) *Dao {

conn, err := newNatsClient(c.Nats.NatsAddr, c.Nats.LiftAddr, c.Nats.Channel, c.Nats.ChannelID)
if err != nil {
Expand Down
6 changes: 4 additions & 2 deletions internal/nats/job/conf/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ type Nats struct {
LiftAddr string
}

type NatsConfig = Nats

var (
confPath string
region string
Expand Down Expand Up @@ -108,14 +110,14 @@ func Default() *Config {
Region: "china",
Zone: "gd",
DeployEnv: "dev",
Host: "test_server",
Host: "job",
},
Discovery: &naming.Config{
Nodes: []string{"127.0.0.1:7171"},
Region: "china",
Zone: "gd",
Env: "dev",
Host: "test_server",
Host: "discovery",
},
Comet: &Comet{
RoutineChan: 1024,
Expand Down
Loading

0 comments on commit 93d18e2

Please sign in to comment.