Reorganize main package structure per discussion

This commit is contained in:
Justin Li 2014-07-16 20:33:38 -04:00
parent e219176e8b
commit f8047ef8ab
3 changed files with 21 additions and 12 deletions

View file

@ -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: To use an external driver, make your own package and call it something like `github.com/yourusername/chihaya`. Then, import Chihaya like so:
```go ```go
package chihaya // This is your own chihaya package. package main
import ( 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. _ "github.com/yourusername/chihaya-custom-backend" // Import any of your own drivers.
) )
func main() { func main() {
c.Boot() // Start Chihaya normally. chihaya.Boot() // Start Chihaya normally.
} }
``` ```

View file

@ -2,7 +2,7 @@
// Use of this source code is governed by the BSD 2-Clause license, // Use of this source code is governed by the BSD 2-Clause license,
// which can be found in the LICENSE file. // which can be found in the LICENSE file.
package main package chihaya
import ( import (
"flag" "flag"
@ -21,13 +21,13 @@ import (
) )
var ( var (
maxprocs int maxProcs int
profile string profile string
configPath string configPath string
) )
func init() { 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(&profile, "profile", "", "if non-empty, path to write profiling data")
flag.StringVar(&configPath, "config", "", "path to the configuration file") flag.StringVar(&configPath, "config", "", "path to the configuration file")
} }
@ -37,8 +37,8 @@ func Boot() {
flag.Parse() flag.Parse()
runtime.GOMAXPROCS(maxprocs) runtime.GOMAXPROCS(maxProcs)
glog.V(1).Info("Set max threads to ", maxprocs) glog.V(1).Info("Set max threads to ", maxProcs)
if profile != "" { if profile != "" {
f, err := os.Create(profile) f, err := os.Create(profile)
@ -70,7 +70,3 @@ func Boot() {
http.Serve(cfg) http.Serve(cfg)
glog.Info("Gracefully shut down") glog.Info("Gracefully shut down")
} }
func main() {
Boot()
}

13
cmd/chihaya/main.go Normal file
View file

@ -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()
}