Example #1
0
func main() {
	s := wcg.NewLocalServer()
	// middleware configuration
	// s.Routes.Before(...)

	// Application Routes
	s.Routes().Get("/", func(res *wcg.Response, req *wcg.Request) {
		res.WriteString("Hello World\n")
	})
	// middleware configuration
	s.Routes().After(middleware.AccessLog(os.Stdout, ""))

	// starting server
	s.Run()
	fmt.Printf("[%d] Server started at %s\n", os.Getpid(), s.Addr)

	// Wait for SIGINT (Ctrl-c) or SIGTERM(kill pid) to quit.
	c := make(chan os.Signal, 1)
	signal.Notify(c)
	for {
		sig := <-c
		if sig == os.Interrupt || sig == syscall.SIGTERM {
			s.Stop(true)
			fmt.Printf("Stopped.\n")
			os.Exit(0)
		}
	}
}
Example #2
0
func StartMockServer(dir string, f func(*MockServer)) {
	server := wcg.NewLocalServer()
	server.Addr = "" // use random port.
	if err := server.Run(); err != nil {
		panic(err)
	}
	defer server.Stop(false)
	f(&MockServer{*server})
}