2015-01-14 03:43:45 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2015-01-14 07:14:00 +08:00
|
|
|
"flag"
|
2015-01-14 03:43:45 +08:00
|
|
|
"log"
|
|
|
|
"sync"
|
|
|
|
|
|
|
|
"github.com/mholt/caddy/config"
|
|
|
|
"github.com/mholt/caddy/server"
|
|
|
|
)
|
|
|
|
|
2015-01-19 14:11:21 +08:00
|
|
|
var conf string
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
flag.StringVar(&conf, "conf", server.DefaultConfigFile, "the configuration file to use")
|
|
|
|
}
|
|
|
|
|
2015-01-14 03:43:45 +08:00
|
|
|
func main() {
|
|
|
|
var wg sync.WaitGroup
|
|
|
|
|
2015-01-14 07:14:00 +08:00
|
|
|
flag.Parse()
|
|
|
|
|
|
|
|
vhosts, err := config.Load(conf)
|
2015-01-14 03:43:45 +08:00
|
|
|
if err != nil {
|
|
|
|
if config.IsNotFound(err) {
|
|
|
|
vhosts = config.Default()
|
|
|
|
} else {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, conf := range vhosts {
|
|
|
|
s, err := server.New(conf)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
wg.Add(1)
|
|
|
|
go func(s *server.Server) {
|
|
|
|
defer wg.Done()
|
|
|
|
err := s.Serve()
|
|
|
|
if err != nil {
|
2015-03-29 06:24:00 +08:00
|
|
|
log.Println(err)
|
2015-01-14 03:43:45 +08:00
|
|
|
}
|
|
|
|
}(s)
|
|
|
|
}
|
|
|
|
|
|
|
|
wg.Wait()
|
|
|
|
}
|