Repository navigation
Getting Started
Thanatat Tamtan edited this page Aug 21, 2018
·
9 revisions
Hime web server can start very easy 😀
package main
import (
"log"
"github.com/acoshift/hime"
)
func main() {
err := hime.New().
Address(":8080").
ListenAndServe()
if err != nil {
log.Fatal(err)
}
}Above code will start a web server using http.DefaultServeMux as handler at address :8080
package main
import (
"log"
"net/http"
"github.com/acoshift/hime"
)
func main() {
h := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("Hello, Hime!"))
})
err := hime.New().
Handler(h).
Address(":8080").
ListenAndServe()
if err != nil {
log.Fatal(err)
}
}Above code is set h as handler
You can use net/http handler to work with hime like above example.
But if you want to use hime.Handler for your handler you can using hime.Handler to wrap
hime-style handler into http.Handler
package main
import (
"log"
"github.com/acoshift/hime"
)
func main() {
h := hime.Handler(func(ctx *hime.Context) error {
return ctx.String("Hello, Hime!")
})
err := hime.New().
Handler(h).
Address(":8080").
ListenAndServe()
if err != nil {
log.Fatal(err)
}
}