鍓嶆彁宸ヤ綔
鐜鎼缓锛屽彲浠ュ弬鑰冨涓嬩袱绡囨暀绋嬶細
鎼缓Go璇█鐜1
鎼缓Go璇█鐜2
瀹夎beego
beego 鐨勫畨瑁呮槸鍏稿瀷鐨 Go 瀹夎鍖呯殑褰㈠紡锛欬/p>
go get github.com/astaxie/beego
甯歌闂锛欬/p>
- git https 鏃犳硶鑾峰彇锛岃閰嶇疆鏈湴鐨 git锛屽叧闂 https 楠岃瘉锛欬/li>
git config --global http.sslVerify false
- 濡傚洜涓虹綉缁滈棶棰樻棤娉曚笅杞斤紝璇峰弬鑰冧笅闈㈢殑
婧愮爜涓嬭浇鍗囩骇
鏂瑰紡
beego 鍗囩骇鍒嗕负 go 鏂瑰紡鍗囩骇鍜屾簮鐮佷笅杞藉崌绾э細
- Go 鍗囩骇锛岄€氳繃璇ユ柟寮忕敤鎴峰彲浠ュ崌绾 beego 妗嗘灦锛屽己鐑堟帹鑽愯鏂瑰紡锛欬/li>
go get -u github.com/astaxie/beego
- 婧愮爜涓嬭浇鍗囩骇锛岀敤鎴疯闂?nbsp;https://github.com/astaxie/beego ,涓嬭浇婧愮爜锛岀劧鍚庤鐩栧埌 $GOPATH/src/github.com/astaxie/beego 鐩綍锛岀劧鍚庨€氳繃鏈湴鎵ц瀹夎灏卞彲浠ュ崌绾т簡锛欬/li>
go install github.com/astaxie/beego
瀹夎bee宸ュ叿
bee 宸ュ叿鏄竴涓负浜嗗崗鍔╁揩閫熷紑鍙 beego 椤圭洰鑰屽垱寤虹殑椤圭洰锛岄€氳繃 bee 鎮ㄥ彲浠ュ緢瀹规槗鐨勮繘琛 beego 椤圭洰鐨勫垱寤恒€佺儹缂栬瘧銆佸紑鍙戙€佹祴璇曘€佸拰閮ㄧ讲銆侟/p>
閫氳繃濡備笅鐨勬柟寮忓畨瑁 bee 宸ュ叿锛欬/p>
go get github.com/beego/bee
瀹夎瀹屼箣鍚庯紝bee鍙墽琛屾枃浠堕粯璁ゅ瓨鏀惧湪 $GOPATH/bin
閲岄潰锛屾墍浠ラ渶瑕佹妸$GOPATH/bin
娣诲姞鍒版偍鐨勭幆澧冨彉閲忎腑锛屾墠鍙互杩涜涓嬩竴姝ャ€侟br>鍦ㄥ懡浠よ杈撳叆bee
,濡傛灉鍑虹幇濡備笅淇℃伅鍒欒〃绀哄畨瑁呮垚鍔烖/p>
鎴戜滑鍙互鍦?code>GOPATH/bin鐩綍涓嬫壘鍒扮敓鎴愮殑bee.exe
鍙墽琛屾枃浠讹紝濡備笅锛欬/p>
鏂板缓beego web椤圭洰
new
鍛戒护鏄柊寤轰竴涓 Web 椤圭洰锛屽湪鍛戒护杈撳叆bee new <椤圭洰鍚?gt;
锛屾瘮濡傛垜浠緭鍏ュ懡浠|code>bee new myapp锛岃繍琛岀粨鏋滃涓嬶細
bee宸ュ叿浼氳嚜鍔ㄥ湪$GOPATH/src
鐩綍涓嬬敓鎴恗yapp椤圭洰锛屽涓嬶細
鍚姩椤圭洰
鍛戒护绐楀彛瀹氫綅鍒癿yapp鐩綍涓嬶紝杩愯鍛戒护bee run
鍗冲彲鍚姩椤圭洰
鍚姩鎴愬姛锛岀孩妗嗛儴鍒嗘樉绀洪」鐩繍琛岀鍙d负8080锛屾垜浠€氳繃娴忚鍣ㄨ闂細localhost:8080锛屽嵆鍙繘鍏ュ涓嬬晫闈↑/p>
鍐欎竴涓猦ello world
鐢╥dea鎵撳紑璇ラ」鐩紝涓嬮潰鏄暣浣撶殑椤圭洰缁撴瀯
鍦╟ontrollers鐩綍涓嬫柊寤篽ello.go鏂囦欢锛屽唴瀹瑰涓嬶細
package controllers
import (
"github.com/astaxie/beego" ) type HelloController struct { beego.Controller //杩欓噷鐩稿綋浜庣户鎵縝eego.Controller } //閲嶅啓Get鏂规硶 func (hello *HelloController) Get() { hello.Ctx.WriteString("hello go") }
涓婇潰鐨勪唬鐮佹樉绀洪鍏堟垜浠0鏄庝簡涓€涓帶鍒跺櫒 HelloController
锛岃繖涓帶鍒跺櫒閲岄潰鍐呭祵浜咟code>beego.Controller锛岃繖灏辨槸 Go 鐨勫祵鍏ユ柟寮忥紝涔熷氨鏄?code>HelloController鑷姩鎷ユ湁浜嗘墍鏈 beego.Controller 鐨勬柟娉曘€傝繖绫讳技浜庨潰鍚戝璞¢噷鐨勭户鎵裤€侟br>鑰孅code>beego.Controller鎷ユ湁寰堝鏂规硶锛屽叾涓寘鎷?code>Init銆丳repare銆丳ost銆丟et銆丏elete銆丠ead绛夋柟娉曘€傛垜浠彲浠ラ€氳繃閲嶅啓鐨勬柟寮忔潵瀹炵幇杩欎簺鏂规硶锛岃€屾垜浠笂闈㈢殑浠g爜灏辨槸閲嶅啓浜咟code>Get鏂规硶銆侟/p>
鐒跺悗灏嗘柊澧炵殑HelloController
娣诲姞璺敱锛屼慨鏀箁outers/router.go鏂囦欢锛屽涓嬶細
package routers
import (
"myapp/controllers" "github.com/astaxie/beego" ) func init() { beego.Router("/", &controllers.MainController{}) // 鏂板璺敱 beego.Router("/hello", &controllers.HelloController{}) }
濂戒簡锛屾帴涓嬫潵鏄笉鏄兂鐫€瑕侀噸鍚」鐩紵涓嶇敤锛宐ee宸ュ叿榛樿涓烘垜浠殑beego椤圭洰瀹炵幇浜嗙儹鍔犺浇锛屾垜浠湪鏉ョ湅鐪嬫帶鍒跺彴
鏀瑰姩浠g爜鏃犻渶閲嶅惎椤圭洰锛岀畝鐩翠笉瑕佸お鐖斤紒
璁╁悗鎴戜滑鎵撳紑娴忚鍣ㄨ緭鍏?a href="http://localhost:8080/hello" target="_blank" rel="nofollow">http://localhost:8080/hello 鐪嬬粨鏋淈/p>
杞嚜 https://www.jianshu.com/p/bdf5bc7e1c6c?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation
来源:oschina
链接:https://my.oschina.net/u/4321531/blog/3485046