From f8047ef8abf2aae843745be327198df9ee1c2886 Mon Sep 17 00:00:00 2001 From: Justin Li Date: Wed, 16 Jul 2014 20:33:38 -0400 Subject: [PATCH] Reorganize main package structure per discussion --- README.md | 6 +++--- main.go => chihaya.go | 14 +++++--------- cmd/chihaya/main.go | 13 +++++++++++++ 3 files changed, 21 insertions(+), 12 deletions(-) rename main.go => chihaya.go (87%) create mode 100644 cmd/chihaya/main.go diff --git a/README.md b/README.md index 2d2dd00..ee9e404 100644 --- a/README.md +++ b/README.md @@ -64,16 +64,16 @@ Backend: To use an external driver, make your own package and call it something like `github.com/yourusername/chihaya`. Then, import Chihaya like so: ```go -package chihaya // This is your own chihaya package. +package main import ( - c "github.com/chihaya/chihaya" // Use an alternate name to avoid the conflict. + "github.com/chihaya/chihaya" _ "github.com/yourusername/chihaya-custom-backend" // Import any of your own drivers. ) func main() { - c.Boot() // Start Chihaya normally. + chihaya.Boot() // Start Chihaya normally. } ``` diff --git a/main.go b/chihaya.go similarity index 87% rename from main.go rename to chihaya.go index 721f0d9..149bfdb 100644 --- a/main.go +++ b/chihaya.go @@ -2,7 +2,7 @@ // Use of this source code is governed by the BSD 2-Clause license, // which can be found in the LICENSE file. -package main +package chihaya import ( "flag" @@ -21,13 +21,13 @@ import ( ) var ( - maxprocs int + maxProcs int profile string configPath string ) func init() { - flag.IntVar(&maxprocs, "maxprocs", runtime.NumCPU(), "maximum parallel threads") + flag.IntVar(&maxProcs, "maxprocs", runtime.NumCPU(), "maximum parallel threads") flag.StringVar(&profile, "profile", "", "if non-empty, path to write profiling data") flag.StringVar(&configPath, "config", "", "path to the configuration file") } @@ -37,8 +37,8 @@ func Boot() { flag.Parse() - runtime.GOMAXPROCS(maxprocs) - glog.V(1).Info("Set max threads to ", maxprocs) + runtime.GOMAXPROCS(maxProcs) + glog.V(1).Info("Set max threads to ", maxProcs) if profile != "" { f, err := os.Create(profile) @@ -70,7 +70,3 @@ func Boot() { http.Serve(cfg) glog.Info("Gracefully shut down") } - -func main() { - Boot() -} diff --git a/cmd/chihaya/main.go b/cmd/chihaya/main.go new file mode 100644 index 0000000..42a2855 --- /dev/null +++ b/cmd/chihaya/main.go @@ -0,0 +1,13 @@ +// Copyright 2014 The Chihaya Authors. All rights reserved. +// Use of this source code is governed by the BSD 2-Clause license, +// which can be found in the LICENSE file. + +package main + +import ( + "github.com/chihaya/chihaya" +) + +func main() { + chihaya.Boot() +}