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/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
}

View File

@ -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
}

View File

@ -1,4 +1,4 @@
package common
package gocommon
import (
"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 (
"context"

View File

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

View File

@ -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
}

View File

@ -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
}

View File

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

View File

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