Пример #1
0
Файл: cgi.go Проект: roca/GO
func main() {
	if err := cgi.Serve(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		header := w.Header()
		header.Set("Content-Type", "text/html; charset=utf-8")
		fmt.Fprintln(w, "Method:", r.Method, "<br/>")
		fmt.Fprintln(w, "URL:", r.URL.String(), "<br/>")
		query := r.URL.Query()
		for k := range query {
			fmt.Fprintln(w, "Query", k+":", query.Get(k), "<br/>")
		}
		r.ParseForm()
		form := r.Form
		for k := range form {
			fmt.Fprintln(w, "Form", k+":", form.Get(k), "<br/>")
		}
		post := r.PostForm
		for k := range post {
			fmt.Fprintln(w, "PostForm", k+":", post.Get(k), "<br/>")
		}
		fmt.Fprintln(w, "RemoteAddr:", r.RemoteAddr, "<br/>")
		if referer := r.Referer(); len(referer) > 0 {
			fmt.Fprintln(w, "Referer:", referer, "<br/>")
		}
		if ua := r.UserAgent(); len(ua) > 0 {
			fmt.Fprintln(w, "UserAgent:", ua, "<br/>")
		}
		for _, cookie := range r.Cookies() {
			fmt.Fprintln(w, "Cookie", cookie.Name+":", cookie.Value, cookie.Path, cookie.Domain, cookie.RawExpires, "<br/>")
		}

		fmt.Fprintln(w, "<!DOCTYPE HTML><html><h1>This output is from a go program over ssl !</h1></html>")
	})); err != nil {
		fmt.Println(err)
	}
}
Пример #2
0
func main() {
	if err := cgi.Serve(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		header := w.Header()
		header.Set("Content-Type", "text/plain; charset=utf-8")
		fmt.Fprintln(w, "Method:", r.Method)
		fmt.Fprintln(w, "URL:", r.URL.String())
		query := r.URL.Query()
		for k := range query {
			fmt.Fprintln(w, "Query", k+":", query.Get(k))
		}
		r.ParseForm()
		form := r.Form
		for k := range form {
			fmt.Fprintln(w, "Form", k+":", form.Get(k))
		}
		post := r.PostForm
		for k := range post {
			fmt.Fprintln(w, "PostForm", k+":", post.Get(k))
		}
		fmt.Fprintln(w, "RemoteAddr:", r.RemoteAddr)
		if referer := r.Referer(); len(referer) > 0 {
			fmt.Fprintln(w, "Referer:", referer)
		}
		if ua := r.UserAgent(); len(ua) > 0 {
			fmt.Fprintln(w, "UserAgent:", ua)
		}
		for _, cookie := range r.Cookies() {
			fmt.Fprintln(w, "Cookie", cookie.Name+":", cookie.Value, cookie.Path, cookie.Domain, cookie.RawExpires)
		}
	})); err != nil {
		fmt.Println(err)
	}
}
Пример #3
0
func main() {

	err := cgi.Serve(http.HandlerFunc(handler))

	if err != nil {
		view.ViewFail("request")
	}

}
Пример #4
0
func serve(handler http.Handler, cgiName string) error {
	switch cgiName {
	case "cgi":
		return cgi.Serve(handler)
	case "fcgi":
		return fcgi.Serve(nil, handler)
	case "standalone":
		return http.ListenAndServe(":8080", handler)
	}

	//TODO: Actually return new error
	return nil
}
Пример #5
0
func main() {
	if err := Cfg.Load("../config/global.json"); err != nil {
		log.Fatal(err)
	}
	r := mux.NewRouter().StrictSlash(false)
	s := r.PathPrefix(Cfg.BasePath).Subrouter()
	st := s.PathPrefix("/testimonials").Subrouter()
	blog.NewBlogSimple("testimonials", st)
	sb := s.PathPrefix("/blag").Subrouter()
	blog.NewBlogSimple("blag", sb)
	s.Handle("/", Index{})
	cgi.Serve(r)
}
Пример #6
0
func foo() {
	for i := 0; i < 2; i++ {
		printHello()
		time.Sleep(1 * time.Second)
	}

	// 23) Map highlighting with the types, also the make built-in function.
	var bar map[string]string
	bar = make(map[string]string)
	bar["foo"] = "bar"

	// 24) Making channels and sending data through them
	c := make(chan int)
	c <- 50

	err := cgi.Serve(nil)
	if err != nil {
		fmt.Printf("%v\n", err.Error())
	}
}
Пример #7
0
// Start CGI, disables Stderr completely. (Due to the way how IIS handlers Stderr)
func StartCGI() error {
	os.Stderr = nil
	return cgi.Serve(Web{})
}
Пример #8
0
func main() {
	// http.HandleFunc("/anders", anders)
	http.HandleFunc("/", versuch)
	cgi.Serve(nil)
}
Пример #9
0
func main() {
	http.HandleFunc("/", randomMove)
	cgi.Serve(nil)
}
Пример #10
0
// Start CGI, disables Stderr completely. (Due to the way how IIS handlers Stderr)
func StartCGI() error {
	os.Stderr = nil
	return cgi.Serve(http.HandlerFunc(nonsecure))
}
Пример #11
0
// Launches CGI execution
func main() {
	cgi.Serve(http.HandlerFunc(pic2html))
}
Пример #12
0
func CGI(hf http.HandlerFunc) error {
	return cgi.Serve(hf)
}
Пример #13
0
func main() {
	err := cgi.Serve(http.HandlerFunc(CGIHandler))
	check(err, "serve CGI request")
}
Пример #14
0
func main() {
	http.HandleFunc("/go-bin/quadratic.cgi", homePage)
	if err := cgi.Serve(http.HandlerFunc(homePage)); err != nil {
		log.Fatal("failed to start server", err)
	}
}
Пример #15
0
func main() {
	// Open the global logger
	logFile, err := os.OpenFile(logFileName, os.O_CREATE|os.O_RDWR|os.O_APPEND, 0660)
	if err != nil {
		return // cannot open log file, abort
	}
	defer logFile.Close()
	logger = log.New(logFile, "", log.Ldate|log.Ltime|log.Lshortfile)

	// Load global configuration
	if err = loadConfig(&config, "config.json"); err != nil {
		logger.Fatalln(err)
	}

	err = cgi.Serve(http.StripPrefix("/cgi-bin/api/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		w.Header().Set("Content-Type", "application/json; charset=utf-8")
		w.Header().Set("Status", "200 OK")

		p := path.Clean(r.URL.Path)

		// POST api/mail
		if m, err := path.Match("mail", p); m && err == nil {
			err = r.ParseForm()
			if err != nil {
				io.WriteString(w, "{\"error\": \""+err.Error()+"\"}")
				logger.Fatalln(err)
			}
			// see https://code.google.com/p/go-wiki/wiki/SendingMail
			// Set up authentication information.
			auth := smtp.PlainAuth(
				"",
				config.SMTPUser,
				config.SMTPPassword,
				config.SMTPHost,
			)
			// Connect to the server, authenticate, set the sender and recipient,
			// and send the email all in one step.
			err := smtp.SendMail(
				config.SMTPHost+":25",
				auth,
				r.PostForm.Get("sender"),
				[]string{config.MailRecipient},
				[]byte(r.PostForm.Get("text")),
			)
			if err != nil {
				io.WriteString(w, "{\"error\": \""+err.Error()+"\"}")
				logger.Fatal(err)
			}
			io.WriteString(w, "{\"status\": \"ok\", \"sender\": \""+r.PostForm.Get("sender")+"\"}")
			return
		}

		// Update database if needed
		updateIfNeeded()

		encoder := json.NewEncoder(w)

		// GET api/car
		if m, err := path.Match("car", p); m && err == nil {
			cars, err := getCars()
			if err != nil {
				outputError(w, err)
			}

			if err = encoder.Encode(cars); err != nil {
				outputError(w, err)
			}
			return
		}

		// GET api/car/<id>
		if m, err := path.Match("car/*", p); m && err == nil {
			id, err := strconv.Atoi(path.Base(p))
			if err != nil {
				outputError(w, err)
			}

			car, err := getCar(id)
			if err != nil {
				outputError(w, err)
			}

			err = encoder.Encode(car)
			if err != nil {
				outputError(w, err)
			}
			return
		}
	})))
	// On error run locally
	if err != nil {
		updateIfNeeded()
	}
}
Пример #16
0
func main() {
	cgi.Serve(http.HandlerFunc(__process__))
}
Пример #17
0
func main() {
	err := cgi.Serve(http.HandlerFunc(CGIHandler))
	if err != nil {
		fmt.Println(err)
	}
}