Run Your Application
Table of contents
Run
You can run your vox application by simply calling the Run
method:
app := vox.New()
app.Run("localhost:3000")
Now your application is listening on port 3000. The Run
method accepts the same arguments as net/http.ListenAndServe
.
Integrate with an existing HTTP server
If you already have an HTTP server in Go, you can integrate vox with it. This can help you migrate to and from vox.
Actually, vox.Application
implements the net/http.Handler
interface. So you can pass a vox.Application
instance to any function that accepts a net/http.Handler
, like http.Handle
:
func rawHandler(w http.ResponseWriter, _ *http.Request) {
io.WriteString(w, "Hello from a raw handler")
}
func voxHandler(ctx *vox.Context, req *vox.Request, res *vox.Response) {
res.Body = "Hello from a vox handler"
}
func main() {
var app = vox.New()
app.Get("/vox", voxHandler)
http.HandleFunc("/raw", rawHandler)
http.Handle("/", app)
http.ListenAndServe("localhost:3000", nil)
}