Simple tool for building RESTful APIs
go get -u github.com/tiny-go/liteYou can use BaseModule that provides basic module functionality (such as register/unregister/list) or write your own implementation. BaseModule already contains Register, Unregister and Controllers methods and implements Module interface.
Any golang func, struct or custom type can be used as a controller provided that it implements Controller interface and has some action methods, such as Get/GetAll/Post/PostAll/... (check the entire list in interfaces.go).
If you need to pass some dependencies (like config, database connection etc) to your module/controller use handler.Map(dep), it will be passed to the module/controller (use struct tag inject:"true" in front of the struct fields that should be injected). Take a look at example folder for more information (for instance example/auth/user/controller.go).
package main
import (
"log"
"net/http"
"github.com/tiny-go/lite"
// register codecs
"github.com/tiny-go/codec/driver"
_ "github.com/tiny-go/codec/driver/json"
_ "github.com/tiny-go/codec/driver/xml"
)
func main() {
// set default codec
driver.Default("application/json")
// create new handler
handler := lite.NewHandler()
// map dependencies
handler.Map(depA)
handler.Map(depB)
handler.Map(depC)
// register modules
handler.Use(aliasOne, moduleA)
handler.Use(aliasTwo, moduleB)
// start HTTP server
log.Fatal(http.ListenAndServe(":8080", handler))
}