Learn from here
The restful protocol can be referred to below, of course, the best, see rails rake routes, the most standard
URL HTTP Verb functionality/object POST Creating Objects/object/ ObjectId GET retrieving Objects/object/objectId PUT Updating Objects /Object GET Queries/object/objectid DELETE Deleting Objects
Direct Sticker Beego Code
App.conf
AppName =8080=true
Router.go
Package Routersimport ( "hello/controllers" "github.com /astaxie/beego") func init () { beego. Restrouter ("/object", &controllers. objectcontroller{}) Beego. Router ("/", &controllers. maincontroller{})}
Objectcontroller.go
Package Controllersimport ("FMT" "Github.com/abbot/go-http-auth" "Github.com/astaxie/beego") Type Objectcontrollerstruct{Beego. Controller}//API apps don't need template rendering, so turn off automatic renderingFunc ( This*Objectcontroller) Prepare () { This. Enablerender =false}func ( This*Objectcontroller) Post () {}func Secret (user, Realmstring)string { ifuser = ="John" { //password is "Hello" return "$1$DLPL2MQE$OQMN16Q49SQDMHENQUNGS1" } return ""}//Basic Auth needs a three-party library to doFunc ( This*Objectcontroller) Get () {authenticate:= Auth. Newbasicauthenticator ("example.com", Secret)ifUsername: = Authenticate. Checkauth ( This. Ctx.request); Username = =""{authenticate. Requireauth ( This. Ctx.responsewriter, This. Ctx.request)}//the parameters inside the URL get this. ctx.input.params[": objectId"] params:= This. Ctx.Input.Params forKey, Value: = Rangeparams{info:= Fmt. Sprintf ("%s:%s\n", key, value) This. Ctx.writestring (Info)}}func ( This*Objectcontroller) Put () {}func ( This*Objectcontroller) Delete () {}
No, it's all in the code.
Create restful APIs based on Beego one-click