From 6c41ff18a7cc4c229518bcd3982ea5c70936e531 Mon Sep 17 00:00:00 2001 From: mountain Date: Mon, 19 Jun 2023 16:19:24 +0900 Subject: [PATCH] =?UTF-8?q?devflag=20=EB=B6=84=EB=A6=AC=20/=20gocommon?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20=ED=8C=A8=ED=82=A4=EC=A7=80=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 --- apicaller/api_caller_auths.go | 6 ------ authcollection.go | 6 +++--- compress.go | 2 +- flags.go | 6 ++++++ locker_redis.go | 2 +- misc.go | 2 +- mongo.go | 7 ++----- redis.go | 4 ++-- reflect_config.go | 2 +- server.go | 2 +- 10 files changed, 18 insertions(+), 21 deletions(-) create mode 100644 flags.go diff --git a/apicaller/api_caller_auths.go b/apicaller/api_caller_auths.go index 7716e97..2061d09 100644 --- a/apicaller/api_caller_auths.go +++ b/apicaller/api_caller_auths.go @@ -7,8 +7,6 @@ import ( "sync" "sync/atomic" "unsafe" - - common "repositories.action2quare.com/ayo/gocommon" ) type ApiCaller interface { @@ -201,10 +199,6 @@ func (ac apiCaller) callByServer() bool { } func (ac apiCaller) HasAuthority(authPath string) bool { - if *common.Devflag { - return true - } - if ac.callByServer() { return true } diff --git a/authcollection.go b/authcollection.go index a373d44..7108972 100644 --- a/authcollection.go +++ b/authcollection.go @@ -1,4 +1,4 @@ -package common +package gocommon import ( "context" @@ -110,7 +110,7 @@ func newAuthCollectionWithRedis(redisClient *redis.Client, subctx context.Contex } if err != nil { - if !*Devflag { + if !*devflag { logger.Error("get maingate config failed :", err) return nil } @@ -131,7 +131,7 @@ func newAuthCollectionWithRedis(redisClient *redis.Client, subctx context.Contex if ttl, ok := config["maingate_session_ttl"].(float64); ok { sessionTTL = int64(ttl) } - } else if !*Devflag { + } else if !*devflag { logger.Error("get maingate config failed :", err) return nil } diff --git a/compress.go b/compress.go index 9d085b9..0bf566a 100644 --- a/compress.go +++ b/compress.go @@ -1,4 +1,4 @@ -package common +package gocommon import ( "archive/tar" diff --git a/flags.go b/flags.go new file mode 100644 index 0000000..d559ce7 --- /dev/null +++ b/flags.go @@ -0,0 +1,6 @@ +package gocommon + +import "flag" + +var commandLine = flag.NewFlagSet("gocommon", flag.ExitOnError) +var devflag = commandLine.Bool("dev", false, "") diff --git a/locker_redis.go b/locker_redis.go index 4613791..3fe838c 100644 --- a/locker_redis.go +++ b/locker_redis.go @@ -1,4 +1,4 @@ -package common +package gocommon import ( "context" diff --git a/misc.go b/misc.go index ad8de74..5381b1a 100644 --- a/misc.go +++ b/misc.go @@ -1,4 +1,4 @@ -package common +package gocommon import ( "encoding/binary" diff --git a/mongo.go b/mongo.go index e7d1510..93ec9e5 100644 --- a/mongo.go +++ b/mongo.go @@ -1,10 +1,9 @@ -package common +package gocommon import ( "context" "encoding/json" "errors" - "flag" "os" "time" @@ -28,8 +27,6 @@ type ConnectionInfo struct { Database string } -var Devflag = flag.Bool("dev", false, "") - type CollectionName string func ParseObjectID(hexstr string) (out primitive.ObjectID) { @@ -42,7 +39,7 @@ func NewMongoConnectionInfo(url string, dbname string) *ConnectionInfo { panic("dbname is empty") } - if *Devflag { + if *devflag { hostname, _ := os.Hostname() dbname = hostname + "-" + dbname } diff --git a/redis.go b/redis.go index fd9302d..627042c 100644 --- a/redis.go +++ b/redis.go @@ -1,4 +1,4 @@ -package common +package gocommon import ( "context" @@ -20,7 +20,7 @@ func newRedisClient(uri string, dbidxoffset int) *redis.Client { } func NewRedisClient(uri string, dbidx int) (*redis.Client, error) { - if !*Devflag { + if !*devflag { return newRedisClient(uri, dbidx), nil } diff --git a/reflect_config.go b/reflect_config.go index f293d0f..5c45159 100644 --- a/reflect_config.go +++ b/reflect_config.go @@ -1,4 +1,4 @@ -package common +package gocommon import ( "encoding/json" diff --git a/server.go b/server.go index a3b71e7..c9e4c42 100644 --- a/server.go +++ b/server.go @@ -1,4 +1,4 @@ -package common +package gocommon import ( "context"