From 667126c5bc2bc78a9a5c5c8a21cdefe0ad708188 Mon Sep 17 00:00:00 2001 From: mountain Date: Wed, 21 Jun 2023 14:38:26 +0900 Subject: [PATCH] =?UTF-8?q?flag=EB=A5=BC=20flagx=EB=A1=9C=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/flag/commandline.go | 15 --------------- core/group_memory.go | 6 ++++-- go.mod | 2 +- go.sum | 2 ++ main.go | 7 +++++-- 5 files changed, 12 insertions(+), 20 deletions(-) delete mode 100644 core/flag/commandline.go diff --git a/core/flag/commandline.go b/core/flag/commandline.go deleted file mode 100644 index 05413f1..0000000 --- a/core/flag/commandline.go +++ /dev/null @@ -1,15 +0,0 @@ -package flag - -import ( - "flag" - "io" - "os" -) - -var commandLine = flag.NewFlagSet("maingate", flag.ContinueOnError) -var Devflag = commandLine.Bool("dev", false, "") - -func init() { - commandLine.SetOutput(io.Discard) - commandLine.Parse(os.Args[1:]) -} diff --git a/core/group_memory.go b/core/group_memory.go index 560ba7b..def455f 100644 --- a/core/group_memory.go +++ b/core/group_memory.go @@ -17,9 +17,9 @@ import ( "sync" "time" + "repositories.action2quare.com/ayo/gocommon/flagx" "repositories.action2quare.com/ayo/gocommon/logger" "repositories.action2quare.com/ayo/gocommon/wshandler" - "repositories.action2quare.com/ayo/tavern/core/flag" "repositories.action2quare.com/ayo/tavern/core/rpc" "github.com/go-redis/redis/v8" @@ -942,6 +942,8 @@ func (gm *groupInMemory) UpdateGroupDocument(gid groupID, body []byte) error { return gm.groupDocSync(gid, newbody) } +var devflag = flagx.Bool("dev", false, "") + func (cfg *groupConfig) prepareInMemory(ctx context.Context, region string, typename string, wsh *wshandler.WebsocketHandler) (group, error) { // group document // member document @@ -953,7 +955,7 @@ func (cfg *groupConfig) prepareInMemory(ctx context.Context, region string, type toHashHex := func(name string) string { hash := md5.New() hash.Write([]byte(name)) - if *flag.Devflag { + if *devflag { hn, _ := os.Hostname() hash.Write([]byte(hn)) } diff --git a/go.mod b/go.mod index bb84ddb..8e7d3c6 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/go-redis/redis/v8 v8.11.5 github.com/gorilla/websocket v1.5.0 go.mongodb.org/mongo-driver v1.11.7 - repositories.action2quare.com/ayo/gocommon v0.0.0-20230620085155-94b6d1499a94 + repositories.action2quare.com/ayo/gocommon v0.0.0-20230621052811-06ef97f11d22 ) require ( diff --git a/go.sum b/go.sum index c50b12b..652e245 100644 --- a/go.sum +++ b/go.sum @@ -104,3 +104,5 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= repositories.action2quare.com/ayo/gocommon v0.0.0-20230620085155-94b6d1499a94 h1:0MwsZfy1DM+ABzQQ9uocN8IZRtdgwbUWwnhDbwnKJMg= repositories.action2quare.com/ayo/gocommon v0.0.0-20230620085155-94b6d1499a94/go.mod h1:ng62uGMGXyQSeuxePG5gJAMtip4Rnspu5Tu7hgvaXns= +repositories.action2quare.com/ayo/gocommon v0.0.0-20230621052811-06ef97f11d22 h1:DImSGNxZrc+Q4WlS1OKMsLAScEfDYLX4XMJdjAaVnXc= +repositories.action2quare.com/ayo/gocommon v0.0.0-20230621052811-06ef97f11d22/go.mod h1:ng62uGMGXyQSeuxePG5gJAMtip4Rnspu5Tu7hgvaXns= diff --git a/main.go b/main.go index e0f783c..a72f5a9 100644 --- a/main.go +++ b/main.go @@ -5,6 +5,7 @@ import ( "context" "net/http" + "repositories.action2quare.com/ayo/gocommon/flagx" "repositories.action2quare.com/ayo/gocommon/wshandler" "repositories.action2quare.com/ayo/tavern/core" @@ -12,6 +13,8 @@ import ( "repositories.action2quare.com/ayo/gocommon/logger" ) +var prefix = flagx.String("prefix", "", "") + func main() { ctx, cancel := context.WithCancel(context.Background()) var config core.TavernConfig @@ -29,8 +32,8 @@ func main() { panic(err) } else { serveMux := http.NewServeMux() - wsh.RegisterHandlers(ctx, serveMux, *common.PrefixPtr) - tv.RegisterHandlers(ctx, serveMux, *common.PrefixPtr) + wsh.RegisterHandlers(ctx, serveMux, *prefix) + tv.RegisterHandlers(ctx, serveMux, *prefix) server := common.NewHTTPServer(serveMux) logger.Println("tavern is started") server.Start()