caddy/main.go

54 lines
873 B
Go
Raw Normal View History

2015-01-14 03:43:45 +08:00
package main
import (
"flag"
2015-01-14 03:43:45 +08:00
"log"
"sync"
"github.com/mholt/caddy/config"
"github.com/mholt/caddy/server"
)
var (
conf string
http2 bool
)
func init() {
flag.StringVar(&conf, "conf", server.DefaultConfigFile, "the configuration file to use")
2015-04-12 06:58:34 +08:00
flag.BoolVar(&http2, "http2", true, "enable HTTP/2 support") // temporary flag until http2 merged into std lib
}
2015-01-14 03:43:45 +08:00
func main() {
var wg sync.WaitGroup
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)
}
2015-04-12 06:58:34 +08:00
s.HTTP2 = http2 // TODO: This setting is temporary
2015-01-14 03:43:45 +08:00
wg.Add(1)
go func(s *server.Server) {
defer wg.Done()
err := s.Serve()
if err != nil {
log.Println(err)
2015-01-14 03:43:45 +08:00
}
}(s)
}
wg.Wait()
}