flag 처리

This commit is contained in:
2023-06-21 10:03:22 +09:00
parent 75c65f2f75
commit ed905a3722
6 changed files with 74 additions and 41 deletions

15
core/flag/commandline.go Normal file
View File

@ -0,0 +1,15 @@
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:])
}

View File

@ -17,9 +17,9 @@ import (
"sync"
"time"
common "repositories.action2quare.com/ayo/gocommon"
"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"
@ -953,7 +953,7 @@ func (cfg *groupConfig) prepareInMemory(ctx context.Context, region string, type
toHashHex := func(name string) string {
hash := md5.New()
hash.Write([]byte(name))
if *common.Devflag {
if *flag.Devflag {
hn, _ := os.Hostname()
hash.Write([]byte(hn))
}
@ -1170,7 +1170,7 @@ func (cfg *groupConfig) prepareInMemory(ctx context.Context, region string, type
call := func() {
method, ok := reflect.TypeOf(gm).MethodByName(fn)
if !ok {
logger.Println("%s message decode failed :", targetbt, msg.Payload, err)
logger.Printf("%s message decode failed :", targetbt, msg.Payload, err)
}
args := []reflect.Value{

View File

@ -3,7 +3,6 @@ package core
import (
"context"
"errors"
"flag"
"io"
"net"
"net/http"
@ -144,10 +143,6 @@ func getMacAddr() (string, error) {
// New :
func New(context context.Context, wsh *wshandler.WebsocketHandler, inconfig *TavernConfig) (*Tavern, error) {
if !flag.Parsed() {
flag.Parse()
}
if inconfig == nil {
var loaded TavernConfig
if err := common.LoadConfig(&loaded); err != nil {