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