Пример #1
0
func TestRPC(t *testing.T) {
	srv, err := server.NewServerEasy("0.0.0.0:3300")
	if err != nil {
		t.Fatalf("starting server: %s", err)
	}
	rpcs := NewRPC()
	err = rpcs.RegisterName("s", &Service{})
	if err != nil {
		t.Fatalf("service register: %s", err)
	}
	srv.AddSub("/api/", rpcs)
	srv.Launch()
}
Пример #2
0
func main() {
	fmt.Fprintf(os.Stderr, "Faff — 2011 — by Petar Maymounkov, [email protected]\n")
	flag.Parse()
	MonitorMemProfile()
	if *flagPprof != "" {
		pprof.StartLogging(*flagPprof, 30*60*1e9) // Once every 30 mins
	}

	config, err := ParseSiteConfig(*flagConfig)
	if err != nil {
		log.Printf("Problem reading config file: %s\n", err)
		os.Exit(1)
	}

	postman = NewPostMan(*flagGIT, *flagStaticDir, *flagDir, *flagMode, config)
	err = postman.RefreshFS()
	if err != nil {
		log.Printf("Problem starting postman: %s\n", err)
		os.Exit(1)
	}

	srv, err := server.NewServerEasy(*flagBind)
	if err != nil {
		log.Printf("Problem binding WWW server: %s\n", err)
		os.Exit(1)
	}
	srv.AddSub("/s/", subs.NewStaticSub(*flagStaticDir))
	srv.AddSub("/t/", subs.NewStaticSub(*flagSiteDir))
	fmt.Printf("Faff server running ...\n")
	for {
		q, err := srv.Read()
		if err != nil {
			log.Printf("Problem responding to %s: %s\n", q.Req.RawURL, err)
			srv.Shutdown()
			os.Exit(1)
		}
		var resp *http.Response
		url := q.Req.URL
		if url == nil {
			resp = http.NewResponse404String(q.Req, "could not parse URL")
		} else {
			resp, err = respond(q.Req, url)
			if err != nil {
				resp = http.NewResponse404String(q.Req, err.String())
			}
		}
		q.ContinueAndWrite(resp)
	}
}
Пример #3
0
func main() {
	fmt.Fprintf(os.Stderr, "ShelfLife Server — 2011\n")
	flag.Parse()
	InstallCtrlCPanic()

	// Connect to database
	log.Printf("Connecting to DB ...")
	db, err := db.NewDb(*flagDbAddr, "shelflife")
	if err != nil {
		log.Fatalf("Problem connecting to db: %s", err)
	}

	// Start web server
	log.Printf("Starting web server ...")
	srv, err := server.NewServerEasy(*flagBind)
	if err != nil {
		log.Fatalf("Problem binding server: %s\n", err)
	}

	// Attach static file server
	mime.AddExtensionType(".x-jquery-tmpl", "text/x-jquery-tmpl")
	if *flagStatic != "" {
		srv.AddSub("/s/", static.NewStaticSub(*flagStatic))
	}

	// Attach RPC server module
	rpcsub := rpc.NewRPC()
	if err := rpcsub.RegisterName("ss", sociability.NewAPI(db, []byte{1, 2, 3, 4})); err != nil {
		log.Fatalf("Problem registering social API: %s\n", err)
	}
	srv.AddSub("/api/", rpcsub)

	log.Printf("Serving %d requests in parallel ...\n", *flagParallel)
	srv.Launch(*flagParallel)
	<-make(chan int)
}