示例#1
0
// NewConn creates and returns a new piladb connection.
func NewConn() *Conn {
	conn := &Conn{}
	conn.Pila = pila.NewPila()
	conn.Config = config.NewConfig().Default()
	conn.Status = NewStatus(version.CommitHash(), time.Now(), MemStats())
	return conn
}
示例#2
0
func TestRootHandler(t *testing.T) {
	conn := NewConn()
	request, err := http.NewRequest("GET", "/", nil)
	if err != nil {
		t.Fatal(err)
	}
	response := httptest.NewRecorder()
	expectedRedirAddress := fmt.Sprintf("https://raw.githubusercontent.com/fern4lvarez/piladb/%s/pilad/README.md", version.CommitHash())

	conn.rootHandler(response, request)

	if response.Code != http.StatusMovedPermanently {
		t.Errorf("response code is %v, expected %v", response.Code, http.StatusMovedPermanently)
	}

	locations, ok := response.Header()["Location"]
	if !ok {
		t.Fatal("no Location Header found")
	}

	if l := len(locations); l != 1 {
		t.Fatalf("number of redirections is %d, expected %d", l, 1)
	}

	if l := locations[0]; l != expectedRedirAddress {
		t.Errorf("redirection Address is %s, expected %s", l, expectedRedirAddress)
	}

}
示例#3
0
// rootHandler redirects to the pilad documentation site hosted on Github.
func (c *Conn) rootHandler(w http.ResponseWriter, r *http.Request) {
	redirAddress := fmt.Sprintf("https://raw.githubusercontent.com/fern4lvarez/piladb/%s/pilad/README.md", version.CommitHash())
	log.Println(r.Method, r.URL, http.StatusMovedPermanently, "Moved to", redirAddress)
	http.Redirect(w, r, redirAddress, http.StatusMovedPermanently)
}