示例#1
0
文件: server.go 项目: fkasper/core
func main() {
	mux := http.NewServeMux()
	mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		w.Header().Set("Content-Type", "application/json")
		w.Write([]byte("{\"hello\": \"world\"}"))
	})

	// Use default options
	handler := cors.Default().Handler(mux)
	http.ListenAndServe(":8080", handler)
}
示例#2
0
文件: service.go 项目: fkasper/core
func (s *Service) startApi() error {
	addr := fmt.Sprintf("%s:%d", s.options.Interface, s.options.Port)
	handler := cors.Default().Handler(s.apiApp.GetHandler())

	//go func() {

	//}()

	server := &http.Server{
		Addr:           addr,
		Handler:        handler,
		ReadTimeout:    s.options.ServerReadTimeout,
		WriteTimeout:   s.options.ServerWriteTimeout,
		MaxHeaderBytes: 1 << 20,
	}

	s.apiServer = manners.NewWithServer(server)
	return s.apiServer.ListenAndServe()
}