Esempio n. 1
0
func ExampleParseIdFromUrl() {
	r, err := http.NewRequest("GET", "https://localhost/users/uid_12345", nil)
	if err != nil {
		panic(err)
	}
	uid, ok := x.ParseIdFromUrl(r, "/users/")
	if !ok {
		panic("Unable to parse uid")
	}
	fmt.Println(uid)

	r, err = http.NewRequest("GET", "https://localhost/users/uid_12345/", nil)
	if err != nil {
		panic(err)
	}
	uid, ok = x.ParseIdFromUrl(r, "/users/")
	if !ok {
		panic("Unable to parse uid")
	}
	fmt.Println(uid)

	// Output:
	// uid_12345
	// uid_12345/
}
Esempio n. 2
0
func read(w http.ResponseWriter, r *http.Request) {
	id, ok := x.ParseIdFromUrl(r, "/read/")
	if !ok {
		return
	}

	// API usage to read data.
	q := api.NewQuery("hack", id).UptoDepth(10)
	result, err := q.Run(c)
	if err != nil {
		x.SetStatus(w, x.E_ERROR, err.Error())
		return
	}
	result.WriteJsonResponse(w)
}