本文整理汇总了Golang中server.NewServer函数的典型用法代码示例。如果您正苦于以下问题:Golang NewServer函数的具体用法?Golang NewServer怎么用?Golang NewServer使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewServer函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
flag.Parse()
// Always use the maximum available CPU/Cores
runtime.GOMAXPROCS(runtime.NumCPU())
if !initLogger() {
return
}
if !initDatabases() {
return
}
// init action
if !handler.InitAction() {
return
}
if !world.InitWorld() {
return
}
gameServer := server.NewServer()
gameServer.Start()
}
示例2: NewCenter
func NewCenter() *Center {
flag.StringVar(&host, "host", "127.0.0.1", "blance host.")
flag.StringVar(&port, "port", "8090", "blance port.")
return &Center{
server: server.NewServer(),
cmanager: mclient.NewManager(),
}
}
示例3: NewCoServer
func NewCoServer() *CoServer {
ctx := context.GetContext()
coServ, ok := ctx.GetComponent("coserver").(*CoServer)
if ok == true {
return coServ
}
serv := server.NewServer()
coServ = &CoServer{serv}
seelog.Infof("<%v> component server created", ctx.GetServerID())
return coServ
}
示例4: main
func main() {
srv := server.NewServer(&opts)
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
srv.Main()
<-sigChan
//srv.logf("jon_server quit")
}
示例5: main
func main() {
flags := parseFlags()
config, err := readFromFile(flags.ConfigFile)
if err != nil {
log.Println("[warn] Can't read the configuration file")
log.Println("[warn] Falling back on default values for configuration.")
}
app := server.NewServer(config)
app.Start()
}
示例6: main
func main() {
echoSrv := &EchoServer{}
var downAddrs []string = []string{"0.0.0.0:1234", "0.0.0.0:2345"}
srv := server.NewServer(echoSrv, "0.0.0.0:5678", downAddrs, 5000)
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM)
srv.Main()
<-sigChan
srv.Exit()
}
示例7: main
func main() {
flag.Parse()
if *master == "" || *startargs == "" {
flag.PrintDefaults()
panic("args error")
}
App.Server = server.NewServer(App, int32(*appid))
if App.Start(*master, *localip, *outerip, *typ, *startargs) {
App.Wait()
}
}
示例8: main
func main() {
config.InitConfig()
if config.EnableProfile {
defer profile.Start(profile.CPUProfile).Stop()
}
runtime.GOMAXPROCS(runtime.NumCPU() * 3)
utils.InitLogger()
if config.RC.MySQLEnabled {
query.RC_MySQLConf = config.RC.MySQLConf
query.InitMySQL(query.RC_MySQLConf)
}
server.NewServer()
}
示例9: main
func main() {
srv := server.NewServer(8080)
srv.Start()
}
示例10: main
func main() {
fileName := flag.String("config", "config.toml.sample", "Config file")
wantsVersion := flag.Bool("v", false, "Get version number")
resetRootPassword := flag.Bool("reset-root", false, "Reset root password")
pidFile := flag.String("pidfile", "", "the pid file")
cpuProfiler := flag.String("cpuprofile", "", "filename where cpu profile data will be written")
runtime.GOMAXPROCS(runtime.NumCPU())
flag.Parse()
startProfiler(cpuProfiler)
if wantsVersion != nil && *wantsVersion {
fmt.Printf("InfluxDB v%s (git: %s)\n", version, gitSha)
return
}
config := configuration.LoadConfiguration(*fileName)
setupLogging(config.LogLevel, config.LogFile)
if pidFile != nil && *pidFile != "" {
pid := strconv.Itoa(os.Getpid())
if err := ioutil.WriteFile(*pidFile, []byte(pid), 0644); err != nil {
panic(err)
}
}
log.Info("Starting Influx Server...")
log.Info(`
+---------------------------------------------+
| _____ __ _ _____ ____ |
| |_ _| / _| | | __ \| _ \ |
| | | _ __ | |_| |_ ___ _| | | | |_) | |
| | | | '_ \| _| | | | \ \/ / | | | _ < |
| _| |_| | | | | | | |_| |> <| |__| | |_) | |
| |_____|_| |_|_| |_|\__,_/_/\_\_____/|____/ |
+---------------------------------------------+
`)
os.MkdirAll(config.RaftDir, 0744)
os.MkdirAll(config.DataDir, 0744)
server, err := server.NewServer(config)
if err != nil {
panic(err)
}
if *resetRootPassword {
// TODO: make this not suck
// This is ghetto as hell, but it'll work for now.
go func() {
time.Sleep(2 * time.Second) // wait for the raft server to join the cluster
log.Warn("Resetting root's password to %s", coordinator.DEFAULT_ROOT_PWD)
if err := server.RaftServer.CreateRootUser(); err != nil {
panic(err)
}
}()
}
err = server.ListenAndServe()
if err != nil {
log.Error("ListenAndServe failed: ", err)
}
}
示例11: startServer
func startServer() (*server.Server, string) {
s := server.NewServer("127.0.0.1", 9999, stateCh)
go s.Start()
return s, waitForData("(system)")
}
示例12: main
func main() {
fileName := flag.String("config", "config.sample.toml", "Config file")
wantsVersion := flag.Bool("v", false, "Get version number")
resetRootPassword := flag.Bool("reset-root", false, "Reset root password")
hostname := flag.String("hostname", "", "Override the hostname, the `hostname` config option will be overridden")
raftPort := flag.Int("raft-port", 0, "Override the raft port, the `raft.port` config option will be overridden")
protobufPort := flag.Int("protobuf-port", 0, "Override the protobuf port, the `protobuf_port` config option will be overridden")
pidFile := flag.String("pidfile", "", "the pid file")
repairLeveldb := flag.Bool("repair-ldb", false, "set to true to repair the leveldb files")
runtime.GOMAXPROCS(runtime.NumCPU())
flag.Parse()
version := fmt.Sprintf("InfluxDB v%s (git: %s) (leveldb: %d.%d)", version, gitSha, levigo.GetLevelDBMajorVersion(), levigo.GetLevelDBMinorVersion())
if wantsVersion != nil && *wantsVersion {
fmt.Println(version)
return
}
config := configuration.LoadConfiguration(*fileName)
// override the hostname if it was specified on the command line
if hostname != nil && *hostname != "" {
config.Hostname = *hostname
}
if raftPort != nil && *raftPort != 0 {
config.RaftServerPort = *raftPort
}
if protobufPort != nil && *protobufPort != 0 {
config.ProtobufPort = *protobufPort
}
config.Version = version
setupLogging(config.LogLevel, config.LogFile)
if *repairLeveldb {
log.Info("Repairing leveldb")
files, err := ioutil.ReadDir(config.DataDir)
if err != nil {
panic(err)
}
o := levigo.NewOptions()
defer o.Close()
for _, f := range files {
p := path.Join(config.DataDir, f.Name())
log.Info("Repairing %s", p)
if err := levigo.RepairDatabase(p, o); err != nil {
panic(err)
}
}
}
if pidFile != nil && *pidFile != "" {
pid := strconv.Itoa(os.Getpid())
if err := ioutil.WriteFile(*pidFile, []byte(pid), 0644); err != nil {
panic(err)
}
}
if config.BindAddress == "" {
log.Info("Starting Influx Server %s...", version)
} else {
log.Info("Starting Influx Server %s bound to %s...", version, config.BindAddress)
}
fmt.Printf(`
+---------------------------------------------+
| _____ __ _ _____ ____ |
| |_ _| / _| | | __ \| _ \ |
| | | _ __ | |_| |_ ___ _| | | | |_) | |
| | | | '_ \| _| | | | \ \/ / | | | _ < |
| _| |_| | | | | | | |_| |> <| |__| | |_) | |
| |_____|_| |_|_| |_|\__,_/_/\_\_____/|____/ |
+---------------------------------------------+
`)
os.MkdirAll(config.RaftDir, 0744)
os.MkdirAll(config.DataDir, 0744)
server, err := server.NewServer(config)
if err != nil {
// sleep for the log to flush
time.Sleep(time.Second)
panic(err)
}
if err := startProfiler(server); err != nil {
panic(err)
}
if *resetRootPassword {
// TODO: make this not suck
// This is ghetto as hell, but it'll work for now.
go func() {
time.Sleep(2 * time.Second) // wait for the raft server to join the cluster
log.Warn("Resetting root's password to %s", coordinator.DEFAULT_ROOT_PWD)
if err := server.RaftServer.CreateRootUser(); err != nil {
panic(err)
}
//.........这里部分代码省略.........
示例13: main
func main() {
s := server.NewServer(settings.SERVER, settings.PORT, nil)
s.Start()
}
示例14: main
func main() {
tcp_port := flag.String("p", "11211", "TCP Port to listen (non required - default port is 11211)")
memory_amount_mb := flag.Int("m", 0, "Amount of memory to allocate (MiB)")
daemonize := flag.Bool("d", false, "Run process as background")
// unix_socket := flag.String("s", "", "Unix socket path to listen on (disables network support)")
// unix_perms := flag.String("a", "", "Permissions (in octal format) for Unix socket created with -s option")
listen_ip := flag.String("l", "", "Listen on specified ip addr only; default to any address.")
max_connections := flag.Int("c", 1024, "Use max simultaneous connections;")
udp_port := flag.String("U", "", "UDP Port to listen (default is empty string - which means it is turned off)")
disable_cas := flag.Bool("C", false, "Disabling of cas command support.")
disable_flush := flag.Bool("F", false, "Disabling of flush_all command support.")
help := flag.Bool("h", false, "Show usage manual and list of options.")
verbose := flag.Bool("v", false, "Turning verbosity on. This option includes errors and warnings only.")
deep_verbose := flag.Bool("vv", false, "Turning deep verbosity on. This option includes requests, responses and same output as simple verbosity.")
flag.Parse()
if *help {
// TODO: It should be spread in future.
fmt.Println("MemoranGo - memory caching service.\nusage:\nmemorango -m <memory_to_alloc> [-CvhFvvd]\n" +
"\t[-l <listen_ip>] [-c <limit_connections>] [-p <tcp_port>] [-U <udp_port>]")
return
}
if *memory_amount_mb <= 0 {
fmt.Println("Impossible to run server with incorrect specified amount of available data.")
return
}
var verbosity = 0
if *deep_verbose {
verbosity = 2
} else if *verbose {
verbosity = 1
}
if *daemonize {
var transacted_options = []string{}
dir, _ := filepath.Abs(filepath.Dir(os.Args[0]))
transacted_options = append(transacted_options, filepath.Join(dir, os.Args[0]), "-p", *tcp_port, "-m",
tools.IntToString(int64(*memory_amount_mb)),
"-c", tools.IntToString(int64(*max_connections)))
if len(*listen_ip) > 0 {
transacted_options = append(transacted_options, "-l", *listen_ip)
}
if len(*udp_port) > 0 {
transacted_options = append(transacted_options, "-U", *udp_port)
}
if *disable_cas {
transacted_options = append(transacted_options, "-C")
}
if *disable_flush {
transacted_options = append(transacted_options, "-F")
}
if verbosity == 1 {
transacted_options = append(transacted_options, "-v")
} else if verbosity == 2 {
transacted_options = append(transacted_options, "-vv")
}
transacted_options = append(transacted_options, "&")
fmt.Printf("Run %s daemon at 127.0.0.1:%s with %d MiB allowed memory.\n", tools.VERSION, *tcp_port, *memory_amount_mb)
cmd := exec.Command("/usr/bin/nohup", transacted_options...)
start_err := cmd.Start()
if start_err != nil {
fmt.Println("Status: ", start_err)
}
} else {
fmt.Printf("%d Run %s on 127.0.0.1:%s with %d MiB allowed memory.\n",
os.Getpid(), tools.VERSION, *tcp_port, *memory_amount_mb)
_server := server.NewServer(*tcp_port, *udp_port, *listen_ip, *max_connections, *disable_cas, *disable_flush,
verbosity, int64(*memory_amount_mb)*1024*1024 /* let's convert to bytes */)
_server.RunServer()
defer _server.StopServer()
_server.Wait()
}
}
示例15: main
func main() {
flags := parseFlags()
app := server.NewServer(flags)
app.Start()
}