Ejemplo n.º 1
0
func TestGetSet(t *testing.T) {
	tuple := Tuple{}

	tuple.Set("foo/bar/baz", 1)
	tuple.Set("foo/bar/baz", 2)
	tuple.Set("foo/bar/bad", 3)
	tuple.Set("foo/bax/bad", "4")
	tuple.Set("foo/bax/Bad", "5")

	if to.Int(tuple.Get("foo/bar/baz")) != 2 {
		t.Errorf("Test failed.\n")
	}

	if tuple["foo"].(map[string]interface{})["bax"].(map[string]interface{})["Bad"].(string) != "5" {
		t.Errorf("Test failed.\n")
	}

}
Ejemplo n.º 2
0
// Starts a fastcgi/http server.
func (server *Server) Run() error {

	var err error

	server.serveMux.Handle("/", server)

	domain := "unix"
	addr := to.String(config.Get("server/socket"))

	if addr == "" {
		domain = "tcp"
		addr = fmt.Sprintf("%s:%d", to.String(config.Get("server/bind")), to.Int(config.Get("server/port")))
	}

	server.listener, err = net.Listen(domain, addr)

	if err != nil {
		log.Fatalf("Failed to bind on %s: %s", addr, err.Error())
	}

	defer server.listener.Close()

	log.Printf("%s is ready to dance.\n", server.listener.Addr())
	log.Printf("Stop server with ^C.\n")

	fmt.Fprintf(os.Stderr, "\n")

	switch to.String(config.Get("server/type")) {
	case "fastcgi":
		if err == nil {
			fcgi.Serve(server.listener, server.serveMux)
		} else {
			log.Fatalf("Failed to start FastCGI server.")
		}
	default:
		if err == nil {
			http.Serve(server.listener, server.serveMux)
		} else {
			log.Fatalf("Failed to start HTTP server.")
		}
	}

	return nil
}