本文整理匯總了Golang中github.com/flike/kingshard/proxy/server.Server.Run方法的典型用法代碼示例。如果您正苦於以下問題:Golang Server.Run方法的具體用法?Golang Server.Run怎麽用?Golang Server.Run使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/flike/kingshard/proxy/server.Server
的用法示例。
在下文中一共展示了Server.Run方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: main
func main() {
runtime.GOMAXPROCS(runtime.NumCPU())
flag.Parse()
if len(*configFile) == 0 {
fmt.Println("must use a config file")
return
}
cfg, err := config.ParseConfigFile(*configFile)
if err != nil {
fmt.Printf("parse config file error:%s", err.Error())
return
}
if *logLevel != "" {
setLogLevel(*logLevel)
} else {
setLogLevel(cfg.LogLevel)
}
var svr *server.Server
svr, err = server.NewServer(cfg)
if err != nil {
golog.Error("main", "main", err.Error(), 0)
return
}
sc := make(chan os.Signal, 1)
signal.Notify(sc,
syscall.SIGHUP,
syscall.SIGINT,
syscall.SIGTERM,
syscall.SIGQUIT)
go func() {
sig := <-sc
golog.Info("main", "main", "Got signal", 0, "signal", sig)
golog.GlobalLogger.Close()
svr.Close()
}()
svr.Run()
}
示例2: main
func main() {
fmt.Print(banner)
runtime.GOMAXPROCS(runtime.NumCPU())
flag.Parse()
if len(*configFile) == 0 {
fmt.Println("must use a config file")
return
} else {
fmt.Printf("config file:%s\n", *configFile)
}
cfg, err := config.ParseConfigFile(*configFile)
if err != nil {
fmt.Printf("parse config file error:%v\n", err.Error())
return
}
//when the log file size greater than 1GB, kingshard will generate a new file
if len(cfg.LogPath) != 0 {
fmt.Printf("log dir path:%s\n", cfg.LogPath)
sysFilePath := path.Join(cfg.LogPath, sysLogName)
fmt.Printf("sys log file path:%s\n", sysFilePath)
sysFile, err := golog.NewRotatingFileHandler(sysFilePath, MaxLogSize, 1)
if err != nil {
fmt.Printf("new log file error:%v\n", err.Error())
return
}
golog.GlobalSysLogger = golog.New(sysFile, golog.Lfile|golog.Ltime|golog.Llevel)
sqlFilePath := path.Join(cfg.LogPath, sqlLogName)
sqlFile, err := golog.NewRotatingFileHandler(sqlFilePath, MaxLogSize, 1)
if err != nil {
fmt.Printf("new log file error:%v\n", err.Error())
return
}
fmt.Printf("sql log file path:%s\n", sqlFilePath)
golog.GlobalSqlLogger = golog.New(sqlFile, golog.Lfile|golog.Ltime|golog.Llevel)
}
if *logLevel != "" {
setLogLevel(*logLevel)
} else {
setLogLevel(cfg.LogLevel)
}
var svr *server.Server
svr, err = server.NewServer(cfg)
if err != nil {
golog.Error("main", "main", err.Error(), 0)
golog.GlobalSysLogger.Close()
golog.GlobalSqlLogger.Close()
return
}
sc := make(chan os.Signal, 1)
signal.Notify(sc,
syscall.SIGHUP,
syscall.SIGINT,
syscall.SIGTERM,
syscall.SIGQUIT)
go func() {
sig := <-sc
golog.Info("main", "main", "Got signal", 0, "signal", sig)
golog.GlobalSysLogger.Close()
golog.GlobalSqlLogger.Close()
svr.Close()
}()
svr.Run()
}
示例3: main
func main() {
fmt.Print(banner)
runtime.GOMAXPROCS(runtime.NumCPU())
flag.Parse()
fmt.Printf("Git commit:%s\n", hack.Version)
fmt.Printf("Build time:%s\n", hack.Compile)
if *version {
return
}
if len(*configFile) == 0 {
fmt.Println("must use a config file")
return
}
cfg, err := config.ParseConfigFile(*configFile)
if err != nil {
fmt.Printf("parse config file error:%v\n", err.Error())
return
}
//when the log file size greater than 1GB, kingshard will generate a new file
if len(cfg.LogPath) != 0 {
sysFilePath := path.Join(cfg.LogPath, sysLogName)
sysFile, err := golog.NewRotatingFileHandler(sysFilePath, MaxLogSize, 1)
if err != nil {
fmt.Printf("new log file error:%v\n", err.Error())
return
}
golog.GlobalSysLogger = golog.New(sysFile, golog.Lfile|golog.Ltime|golog.Llevel)
sqlFilePath := path.Join(cfg.LogPath, sqlLogName)
sqlFile, err := golog.NewRotatingFileHandler(sqlFilePath, MaxLogSize, 1)
if err != nil {
fmt.Printf("new log file error:%v\n", err.Error())
return
}
golog.GlobalSqlLogger = golog.New(sqlFile, golog.Lfile|golog.Ltime|golog.Llevel)
}
if *logLevel != "" {
setLogLevel(*logLevel)
} else {
setLogLevel(cfg.LogLevel)
}
var svr *server.Server
svr, err = server.NewServer(cfg)
if err != nil {
golog.Error("main", "main", err.Error(), 0)
golog.GlobalSysLogger.Close()
golog.GlobalSqlLogger.Close()
return
}
sc := make(chan os.Signal, 1)
signal.Notify(sc,
syscall.SIGINT,
syscall.SIGTERM,
syscall.SIGQUIT,
syscall.SIGPIPE,
)
go func() {
for {
sig := <-sc
if sig == syscall.SIGINT || sig == syscall.SIGTERM || sig == syscall.SIGQUIT {
golog.Info("main", "main", "Got signal", 0, "signal", sig)
golog.GlobalSysLogger.Close()
golog.GlobalSqlLogger.Close()
svr.Close()
} else if sig == syscall.SIGPIPE {
golog.Info("main", "main", "Ignore broken pipe signal", 0)
}
}
}()
svr.Run()
}