From 8d7ec29eebd01989ea0e3abd0d28f63082039061 Mon Sep 17 00:00:00 2001 From: Garet Halliday <ghalliday@gfxlabs.io> Date: Fri, 2 Sep 2022 11:50:05 -0500 Subject: [PATCH] add port to tcp --- .gitignore | 1 + cmd/cgat/main.go | 27 +++++++++++++++++++++++++++ go.mod | 1 + go.sum | 3 +++ lib/config/config.go | 16 ++++++++++++++++ lib/gat/gatling.go | 3 ++- 6 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 cmd/cgat/main.go diff --git a/.gitignore b/.gitignore index b4c39034..c5f700c6 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ target +.idea diff --git a/cmd/cgat/main.go b/cmd/cgat/main.go new file mode 100644 index 00000000..4ff4c958 --- /dev/null +++ b/cmd/cgat/main.go @@ -0,0 +1,27 @@ +package main + +import ( + "context" + "gfx.cafe/gfx/pggat/lib/config" + "gfx.cafe/gfx/pggat/lib/gat" +) + +// test config, should be changed +const CONFIG = "./lib/config/config_data.toml" + +func main() { + conf, err := config.Load(CONFIG) + if err != nil { + panic(err) + } + gatling := gat.NewGatling() + err = gatling.ApplyConfig(conf) + if err != nil { + panic(err) + } + + err = gatling.ListenAndServe(context.Background()) + if err != nil { + panic(err) + } +} diff --git a/go.mod b/go.mod index b8b37913..89527a1a 100644 --- a/go.mod +++ b/go.mod @@ -5,6 +5,7 @@ go 1.19 require ( git.tuxpa.in/a/zlog v1.32.0 github.com/BurntSushi/toml v1.2.0 + github.com/ethereum/go-ethereum v1.10.23 github.com/xdg-go/scram v1.1.1 golang.org/x/net v0.0.0-20220826154423-83b083e8dc8b ) diff --git a/go.sum b/go.sum index 744b01d2..64dbb757 100644 --- a/go.sum +++ b/go.sum @@ -3,6 +3,8 @@ git.tuxpa.in/a/zlog v1.32.0/go.mod h1:vUa2Qhu6DLPLqmfRy99FiPqaY2eb6/KQjtMekW3UNn github.com/BurntSushi/toml v1.2.0 h1:Rt8g24XnyGTyglgET/PRUNlrUeu9F5L+7FilkXfZgs0= github.com/BurntSushi/toml v1.2.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= github.com/coreos/go-systemd/v22 v22.3.3-0.20220203105225-a9a7ef127534/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= +github.com/ethereum/go-ethereum v1.10.23 h1:Xk8XAT4/UuqcjMLIMF+7imjkg32kfVFKoeyQDaO2yWM= +github.com/ethereum/go-ethereum v1.10.23/go.mod h1:EYFyF19u3ezGLD4RqOkLq+ZCXzYbLoNDdZlMt7kyKFg= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40= github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4= @@ -16,6 +18,7 @@ github.com/xdg-go/scram v1.1.1 h1:VOMT+81stJgXW3CpHyqHN3AXDYIMsx56mEFrB37Mb/E= github.com/xdg-go/scram v1.1.1/go.mod h1:RaEWvsqvNKKvBPvcKeFjrG2cJqOkHTiyTpzz23ni57g= github.com/xdg-go/stringprep v1.0.3 h1:kdwGpVNwPFtjs98xCGkHjQtGKh86rDcRZN17QEMCOIs= github.com/xdg-go/stringprep v1.0.3/go.mod h1:W3f5j4i+9rC0kuIEJL0ky1VpHXQU3ocBgklLGvcBnW8= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 h1:7I4JAnoQBe7ZtJcBaYHi5UtiO8tQHbUSXxL+pnGRANg= golang.org/x/net v0.0.0-20220826154423-83b083e8dc8b h1:ZmngSVLe/wycRns9MKikG9OWIEjGcGAkacif7oYQaUY= golang.org/x/net v0.0.0-20220826154423-83b083e8dc8b/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk= golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= diff --git a/lib/config/config.go b/lib/config/config.go index d0eecea7..8bbaa2b1 100644 --- a/lib/config/config.go +++ b/lib/config/config.go @@ -1,5 +1,10 @@ package config +import ( + "github.com/BurntSushi/toml" + "os" +) + type PoolMode string const ( @@ -91,3 +96,14 @@ func (o Server) Role() ServerRole { } return ServerRole(SERVERROLE_NONE) } + +func Load(path string) (conf *Global, err error) { + conf = new(Global) + var f []byte + f, err = os.ReadFile(path) + if err != nil { + return + } + err = toml.Unmarshal(f, conf) + return +} diff --git a/lib/gat/gatling.go b/lib/gat/gatling.go index 9349b814..a2176686 100644 --- a/lib/gat/gatling.go +++ b/lib/gat/gatling.go @@ -2,6 +2,7 @@ package gat import ( "context" + "fmt" "net" "gfx.cafe/gfx/pggat/lib/config" @@ -32,7 +33,7 @@ func (g *Gatling) ApplyConfig(c *config.Global) error { } func (g *Gatling) ListenAndServe(ctx context.Context) error { - ln, err := net.Listen("tcp", g.c.General.Host) + ln, err := net.Listen("tcp", fmt.Sprintf("%s:%d", g.c.General.Host, g.c.General.Port)) if err != nil { return err } -- GitLab