一個Go語言的REST API框架:Ripple
Ripple是一個簡單,而且靈活的Go語言 REST API 框架。以下是一個簡單的用法:
package main import ( "./ripple" "./controllers" "net/http" ) func main() { // Build the REST application app := ripple.NewApplication() // Create a controller and register it. Any number of controllers // can be registered that way. userController := rippledemo.NewUserController() app.RegisterController("users", userController) // Setup the routes. The special patterns `_controller` will automatically match // an existing controller, as defined above. Likewise, `_action` will match any // existing action. app.AddRoute(ripple.Route{ Pattern: ":_controller/:id/:_action" }) app.AddRoute(ripple.Route{ Pattern: ":_controller/:id/" }) app.AddRoute(ripple.Route{ Pattern: ":_controller" }) // Start the server http.ListenAndServe(":8080", app) }
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!