devflag 분리 / gocommon으로 패키지 변경

This commit is contained in:
2023-06-19 16:19:24 +09:00
parent c6c9b7727b
commit 6c41ff18a7
10 changed files with 18 additions and 21 deletions

View File

@ -7,8 +7,6 @@ import (
"sync" "sync"
"sync/atomic" "sync/atomic"
"unsafe" "unsafe"
common "repositories.action2quare.com/ayo/gocommon"
) )
type ApiCaller interface { type ApiCaller interface {
@ -201,10 +199,6 @@ func (ac apiCaller) callByServer() bool {
} }
func (ac apiCaller) HasAuthority(authPath string) bool { func (ac apiCaller) HasAuthority(authPath string) bool {
if *common.Devflag {
return true
}
if ac.callByServer() { if ac.callByServer() {
return true return true
} }

View File

@ -1,4 +1,4 @@
package common package gocommon
import ( import (
"context" "context"
@ -110,7 +110,7 @@ func newAuthCollectionWithRedis(redisClient *redis.Client, subctx context.Contex
} }
if err != nil { if err != nil {
if !*Devflag { if !*devflag {
logger.Error("get maingate config failed :", err) logger.Error("get maingate config failed :", err)
return nil return nil
} }
@ -131,7 +131,7 @@ func newAuthCollectionWithRedis(redisClient *redis.Client, subctx context.Contex
if ttl, ok := config["maingate_session_ttl"].(float64); ok { if ttl, ok := config["maingate_session_ttl"].(float64); ok {
sessionTTL = int64(ttl) sessionTTL = int64(ttl)
} }
} else if !*Devflag { } else if !*devflag {
logger.Error("get maingate config failed :", err) logger.Error("get maingate config failed :", err)
return nil return nil
} }

View File

@ -1,4 +1,4 @@
package common package gocommon
import ( import (
"archive/tar" "archive/tar"

6
flags.go Normal file
View File

@ -0,0 +1,6 @@
package gocommon
import "flag"
var commandLine = flag.NewFlagSet("gocommon", flag.ExitOnError)
var devflag = commandLine.Bool("dev", false, "")

View File

@ -1,4 +1,4 @@
package common package gocommon
import ( import (
"context" "context"

View File

@ -1,4 +1,4 @@
package common package gocommon
import ( import (
"encoding/binary" "encoding/binary"

View File

@ -1,10 +1,9 @@
package common package gocommon
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"errors" "errors"
"flag"
"os" "os"
"time" "time"
@ -28,8 +27,6 @@ type ConnectionInfo struct {
Database string Database string
} }
var Devflag = flag.Bool("dev", false, "")
type CollectionName string type CollectionName string
func ParseObjectID(hexstr string) (out primitive.ObjectID) { func ParseObjectID(hexstr string) (out primitive.ObjectID) {
@ -42,7 +39,7 @@ func NewMongoConnectionInfo(url string, dbname string) *ConnectionInfo {
panic("dbname is empty") panic("dbname is empty")
} }
if *Devflag { if *devflag {
hostname, _ := os.Hostname() hostname, _ := os.Hostname()
dbname = hostname + "-" + dbname dbname = hostname + "-" + dbname
} }

View File

@ -1,4 +1,4 @@
package common package gocommon
import ( import (
"context" "context"
@ -20,7 +20,7 @@ func newRedisClient(uri string, dbidxoffset int) *redis.Client {
} }
func NewRedisClient(uri string, dbidx int) (*redis.Client, error) { func NewRedisClient(uri string, dbidx int) (*redis.Client, error) {
if !*Devflag { if !*devflag {
return newRedisClient(uri, dbidx), nil return newRedisClient(uri, dbidx), nil
} }

View File

@ -1,4 +1,4 @@
package common package gocommon
import ( import (
"encoding/json" "encoding/json"

View File

@ -1,4 +1,4 @@
package common package gocommon
import ( import (
"context" "context"