本文整理汇总了Golang中net/http/fcgi.Serve函数的典型用法代码示例。如果您正苦于以下问题:Golang Serve函数的具体用法?Golang Serve怎么用?Golang Serve使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Serve函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
flag.Parse()
loadConfig()
gorest.RegisterService(new(DreamService))
var err error
webClient, err = spicerack.LogIntoSaltyBet(illumEmail, illumPass)
if err != nil {
fmt.Printf("Error logging into Salty Bet: %v\n", err)
}
if !*fastcgi {
fmt.Println("Running Locally")
static := []string{"index", "search", "ds.js", "s.js", "ta.css"}
for _, p := range static {
http.HandleFunc(fmt.Sprintf("/%s", p), staticPage)
}
http.Handle("/", gorest.Handle())
fmt.Println(http.ListenAndServe(":9000", nil))
} else {
fmt.Println("Running as FastCGI")
l, _ := net.Listen("tcp", ":9000")
fmt.Println(fcgi.Serve(l, gorest.Handle()))
}
}
示例2: Run
func (app *App) Run() {
addr := HttpAddr
if HttpPort != 0 {
addr = fmt.Sprintf("%s:%d", HttpAddr, HttpPort)
}
BeeLogger.Info("Running on %s", addr)
var (
err error
l net.Listener
)
if UseFcgi {
if HttpPort == 0 {
l, err = net.Listen("unix", addr)
} else {
l, err = net.Listen("tcp", addr)
}
if err != nil {
BeeLogger.Critical("Listen: ", err)
}
err = fcgi.Serve(l, app.Handlers)
} else {
if EnableHotUpdate {
server := &http.Server{
Handler: app.Handlers,
ReadTimeout: time.Duration(HttpServerTimeOut) * time.Second,
WriteTimeout: time.Duration(HttpServerTimeOut) * time.Second,
}
laddr, err := net.ResolveTCPAddr("tcp", addr)
if nil != err {
BeeLogger.Critical("ResolveTCPAddr:", err)
}
l, err = GetInitListner(laddr)
theStoppable = newStoppable(l)
err = server.Serve(theStoppable)
theStoppable.wg.Wait()
CloseSelf()
} else {
s := &http.Server{
Addr: addr,
Handler: app.Handlers,
ReadTimeout: time.Duration(HttpServerTimeOut) * time.Second,
WriteTimeout: time.Duration(HttpServerTimeOut) * time.Second,
}
if HttpTLS {
err = s.ListenAndServeTLS(HttpCertFile, HttpKeyFile)
} else {
err = s.ListenAndServe()
}
}
}
if err != nil {
BeeLogger.Critical("ListenAndServe: ", err)
time.Sleep(100 * time.Microsecond)
}
}
示例3: FastCGI
func FastCGI(addr string, hf http.HandlerFunc) error {
ln, err := net.Listen("tcp", addr)
if err != nil {
return err
}
return fcgi.Serve(ln, hf)
}
示例4: main
func main() {
log.SetPrefix("gff3validating ")
log.Println("STARTED")
fcgi.Serve(nil, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
log.Println("Got request")
reader, err := r.MultipartReader()
if err != nil {
view.ErrorTmpl.Execute(w, view.Error{err, "The file was not sent or received properly"})
log.Println(err)
return
}
var fname string
for {
part, err := reader.NextPart()
if err == io.EOF {
log.Printf("EOF\n")
break
}
if err != nil {
view.ErrorTmpl.Execute(w, view.Error{err, "The file was not sent or received properly"})
log.Println(err)
return
}
switch part.FormName() {
case "soubor":
f, err := ioutil.TempFile("", "gff")
if err != nil {
view.ErrorTmpl.Execute(w, view.Error{err, "Could not create a temporary file"})
log.Println(err)
}
fname = f.Name()
_, err = io.Copy(f, part)
f.Close()
default:
log.Printf("Unexpected FormName %v\n", part.FormName())
}
// l/*og.Println("FormName: " + part.FormName())
// log.Println*/("FileName: " + part.FileName())
part.Close()
}
if fname != "" {
log.Println("file", fname, "created")
results, err := services.Validate(fname)
if err != nil {
view.ErrorTmpl.Execute(w, view.Error{err, "Running the gt gff3validator command failed"})
} else {
view.ResultsTmpl.Execute(w, results)
}
err = os.Remove(fname)
if err != nil {
log.Println(err)
}
}
}))
}
示例5: main
func main() {
log.Print("main")
listener, _ := net.Listen("tcp", ":9000")
fcgi.Serve(listener, rooter(goji.DefaultMux))
}
示例6: main
func main() {
router := mux.NewRouter()
router.HandleFunc(flagURIPrefix, indexHandler).
Methods("GET").
Name("home")
router.HandleFunc(flagURIPrefix+"/ls", listHandler).
Methods("GET").
Name("list")
router.HandleFunc(flagURIPrefix+"/rm/{path}", deleteHandler).
Methods("GET").
Name("rm")
listener, err := net.Listen("unix", flagFCGISocket)
if err != nil {
log.Fatal("Failed to listen: ", err)
}
defer listener.Close()
err = fcgi.Serve(listener, router)
if err != nil {
log.Fatal("Failed to serve on socket: ", err)
}
return
}
示例7: Run
func (app *App) Run() {
addr := fmt.Sprintf("%s:%d", HttpAddr, HttpPort)
var (
err error
l net.Listener
)
if UseFcgi {
l, err = net.Listen("tcp", addr)
if err != nil {
BeeLogger.Fatal("Listen: ", err)
}
err = fcgi.Serve(l, app.Handlers)
} else {
server := &http.Server{Handler: app.Handlers}
laddr, err := net.ResolveTCPAddr("tcp", addr)
if nil != err {
BeeLogger.Fatal("ResolveTCPAddr:", err)
}
l, err = GetInitListner(laddr)
theStoppable = newStoppable(l)
err = server.Serve(theStoppable)
theStoppable.wg.Wait()
CloseSelf()
}
if err != nil {
BeeLogger.Fatal("ListenAndServe: ", err)
}
}
示例8: main
func main() {
// Run HTTP server
fmt.Println("Domain: " + config.String("server.domain"))
fmt.Println("Start rotator server: " + *flagHost)
if *flagFastCGI {
fmt.Println("FastCGI Mode: ON")
}
if *flagDebug {
fmt.Println("Debug Mode: ON")
}
// Run server
if *flagFastCGI {
if tcp, err := net.Listen("tcp", *flagHost); nil == err {
fcgi.Serve(tcp, router.NewRouter(*flagDebug))
} else if err != nil {
log.Fatal(err)
}
} else {
var err error
http.Handle("/", router.NewRouter(*flagDebug))
http.Handle("/public/", http.FileServer(http.Dir(*flagBaseDir)))
if err = http.ListenAndServe(*flagHost, nil); nil != err {
log.Fatal(err)
}
}
}
示例9: main
func main() {
args := struct{ port string }{}
flag.StringVar(&args.port, "port", "", "The port to serve on.")
flag.Parse()
cache = make(map[string]string, 100)
for i := 0; i < 101; i++ {
s := strconv.Itoa(i)
t := s
f, b := i%3 == 0, i%5 == 0
if f || b {
t = ""
}
if f {
t = "Fizz"
}
if b {
t += "Buzz"
}
cache[s] = t + "\n"
}
http.HandleFunc("/", handler)
switch {
case args.port != "":
if err := http.ListenAndServe(args.port, nil); err != nil {
log.Fatal(err)
}
default:
if err := fcgi.Serve(nil, nil); err != nil {
log.Fatal(err)
}
}
}
示例10: main
func main() {
err := fcgi.Serve(nil, http.HandlerFunc(handler))
//err := http.ListenAndServe("localhost:1234", http.HandlerFunc(handler))
if err != nil {
log.Fatal(err)
}
}
示例11: web_start
func web_start() {
mux := http.NewServeMux()
mux.HandleFunc("/api/1/group", groupV1)
mux.HandleFunc("/api/1/status", statusV1)
mux.HandleFunc("/tablet", user_interface_tabletV1)
mux.HandleFunc("/phone", user_interface_phoneV1)
mux.HandleFunc("/", static_root)
if local_web_server_flag {
hostname := fmt.Sprintf(":%d", web_bind_port)
start_message := fmt.Sprintf("Starting local hued-web on %s\n", hostname)
fmt.Println(start_message)
glog.Infof(start_message)
http.ListenAndServe(hostname, mux)
} else {
hostname := fmt.Sprintf("%s:%d", web_bind_address, web_bind_port)
l, err := net.Listen("tcp", hostname)
if err == nil {
start_message := fmt.Sprintf("Starting hued-web on %s\n", hostname)
fmt.Println(start_message)
glog.Infof(start_message)
fcgi.Serve(l, mux)
} else {
glog.Error("Error starting server, is the port already in use?")
}
}
}
示例12: main
func main() {
socket := "/home/vagrant/dev/src/github.com/r-fujiwara/goroutine-fcgi/go-home.sock"
userid := 33
groupid := 33
_ = syscall.Umask(0177)
l, err := net.Listen("unix", socket)
_ = syscall.Chown(socket, userid, groupid)
defer l.Close()
if err != nil {
log.Fatal(err)
}
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
go func() {
for sig := range c {
log.Printf("Captured: %v", sig)
l.Close()
}
}()
mux := http.NewServeMux()
mux.HandleFunc("/", hello)
fcgi.Serve(l, mux)
}
示例13: Run
func (app *App) Run() {
app.buildTemplate()
if app.config.HttpAddr == "" {
app.config.HttpAddr = "0.0.0.0"
}
addr := fmt.Sprintf("%s:%d", app.config.HttpAddr, app.config.HttpPort)
var err error
for {
if app.config.UseFcgi {
l, e := net.Listen("tcp", addr)
if e != nil {
log.Print("Listen: ", e)
}
//log.Print("UseFcgi, fcgi.Serve")
err = fcgi.Serve(l, app.Handlers)
} else {
//log.Print("http.ListenAndServe")
//err = http.ListenAndServe(addr, app.Handlers)
err = httpListenAndServe(addr, app.Handlers, app.config.ReadTimeout, app.config.WriteTimeout)
}
if err != nil {
log.Print("ListenAndServe: ", err)
//panic(err)
}
time.Sleep(time.Second * 2)
}
}
示例14: NewServer
// NewServer takes a host or ip address string, a port number, read timeout
// (in secords), along with a map defining url string patterns, and their
// corresponding response functions. NewServer sets each map entry into
// the HTTP multiplexer, then starts the HTTP server on the given host/ip
// address and port. The api.Server struct also provides a Logger for each
// response function to use, to log warnings, errors, and other information.
func NewServer(host, transport string, port, timeout int, useFcgi bool, handlers map[string]func(http.ResponseWriter, *http.Request)) {
mux := http.NewServeMux()
for pattern, handler := range handlers {
mux.Handle(pattern, http.HandlerFunc(handler))
}
s := &http.Server{
Addr: fmt.Sprintf("%s:%d", host, port),
Handler: mux,
ReadTimeout: time.Duration(timeout) * time.Second, // to prevent abuse of "keep-alive" requests by clients
}
Srv = &Server{
mux: mux,
s: s,
Logger: log.New(os.Stdout, "", log.Ldate|log.Ltime),
Transport: transport,
}
if useFcgi {
// create a listener for the incoming FastCGI requests
listener, err := net.Listen(Srv.Transport, Srv.s.Addr)
if err != nil {
Srv.Logger.Fatal(err)
}
fcgi.Serve(listener, Srv.mux)
} else {
// serve requests using the default http.Server
Srv.s.ListenAndServe()
}
}
示例15: main
func main() {
if !flag.Parsed() {
flag.Parse()
}
var regexHandler = NewHttpHandlerRegexMatcher()
http.Handle("/", http.StripPrefix(*prefix, regexHandler))
regexHandler.Handle("/test", HttpHandlerRestHandler{5})
regexHandler.Handle("/test/", HttpHandlerRestHandler{5})
regexHandler.Handle("/test/{id}", HttpHandlerRestHandler{5})
regexHandler.Handle("/ses/{request}", oauthFlowHandler{})
var socket = *socket
os.Remove(socket)
oldUmask := syscall.Umask(000)
l, err := net.Listen("unix", socket)
syscall.Umask(oldUmask)
if err != nil {
panic(err)
}
panic(fcgi.Serve(l, http.DefaultServeMux))
}