devflag 분리 / gocommon으로 패키지 변경
This commit is contained in:
@ -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
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
package common
|
package gocommon
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"archive/tar"
|
"archive/tar"
|
||||||
|
|||||||
6
flags.go
Normal file
6
flags.go
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
package gocommon
|
||||||
|
|
||||||
|
import "flag"
|
||||||
|
|
||||||
|
var commandLine = flag.NewFlagSet("gocommon", flag.ExitOnError)
|
||||||
|
var devflag = commandLine.Bool("dev", false, "")
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package common
|
package gocommon
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|||||||
2
misc.go
2
misc.go
@ -1,4 +1,4 @@
|
|||||||
package common
|
package gocommon
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
|
|||||||
7
mongo.go
7
mongo.go
@ -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
|
||||||
}
|
}
|
||||||
|
|||||||
4
redis.go
4
redis.go
@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
package common
|
package gocommon
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
|||||||
Reference in New Issue
Block a user