Skip to content

Commit

Permalink
README auto-gen
Browse files Browse the repository at this point in the history
  • Loading branch information
ant0ine committed Jul 13, 2014
1 parent 0fa371f commit 0a011ed
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ In fact the internal code of **go-json-rest** is itself implemented with Middlew
- [Hello World!](#hello-world)
- [Countries](#countries)
- [Users](#users)
- [Lookup](#lookup)
- [Applications](#applications)
- [API and static files](#api-and-static-files)
- [GORM](#gorm)
Expand Down Expand Up @@ -374,6 +375,52 @@ func (u *Users) DeleteUser(w rest.ResponseWriter, r *rest.Request) {

```

#### Lookup

Demonstrate how to use the relaxed placeholder (notation #paramName).
This placeholder matches everything until the first `/`, including `.`

The curl demo:
```
curl -i http://127.0.0.1:8080/lookup/google.com
curl -i http://127.0.0.1:8080/lookup/notadomain
```

Go code:
``` go
package main

import (
"github.com/ant0ine/go-json-rest/rest"
"log"
"net"
"net/http"
)

type Message struct {
Body string
}

func main() {
handler := rest.ResourceHandler{}
err := handler.SetRoutes(
&rest.Route{"GET", "/lookup/#host", func(w rest.ResponseWriter, req *rest.Request) {
ip, err := net.LookupIP(req.PathParam("host"))
if err != nil {
rest.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.WriteJson(&ip)
}},
)
if err != nil {
log.Fatal(err)
}
log.Fatal(http.ListenAndServe(":8080", &handler))
}

```


### Applications

Expand Down

0 comments on commit 0a011ed

Please sign in to comment.