您的位置 首页 golang

Golang 框架学习:搭建beego

框架简介

beego 是一个快速开发 Go 应用的 HTTP 框架,它可以用来快速开发 API、Web 及后端服务等各种应用,是一个 RESTful 的框架,主要设计灵感来源于 tornado、sinatra 和 flask 这三个框架,但是结合了 Go 本身的一些特性(interface、struct 嵌入等)而设计的一个框架。

我所使用的学习资料:

MVC设计模式

beego是一个典型的MVC设计模式:

  • Model(模型)是应用程序中用于处理应用程序数据逻辑的部分。通常模型对象负责在数据库中存取数据。
  • View(视图)是应用程序中处理数据显示的部分。通常视图是依据模型数据创建的。
  • Controller(控制器)是应用程序中处理用户交互的部分。通常控制器负责从视图读取数据,控制用户输入,并向模型发送数据。

mvc

项目结构

beego框架的结构树如下图所示:

├── conf│
   └── app.conf
   ├── controllers│
   ├── admin│
   └── default.go
├── main.go
├── models│
   └── models.go
├── static│
   ├── css│
   ├── ico│
   ├── img│
   └── js
     └── views
    ├── admin    
└── index.tpl 

从上面的目录结构我们可以看出来 M(models 目录)V(views 目录)C(controllers 目录)的结构, main.go 是入口文件,conf是配置文件目录,controllers是控制器目录、model是model文件存放目录、static是静态资源存放目录,views是界面目录。

搭建教程

现在以 Windows 10 + Golang 1.13 + Jetbrains GoLand 为开发环境演示搭建 beego 框架的教程。

  • 安装

打开 Jetbrains GoLand ( PowerShell也可 ) ,在终端 Terminal 输入以下命令下载 beego包,需要挂载代理

 $ go get -u github.com/astaxie/beego 
 $ go get -u github.com/beego/bee
  • 配置环境变量(如果事先已经配置好 Golang 的开发环境可以跳过这一步)

新建一个用户变量GOPATH,编辑写上你的Golang工作目录(用于存放开发者的工程项目及第三方包);新建一个用户变量GOROOT,填上你的Golang安装路径(根目录)。

GOPATH

【注】:GOPATH可以自定义位置,GOROOT必须遵从Golang的安装路径。

  • 切换工作目录查看当前包

请注意,开发者的Golang源代码文件和第三方包都被保存在GOPATH的src文件夹下。可切换至工作目录查看beego包是否已经下载成功。

$ cd $GOPATH/src$ cd github.com
$ ls

ls beego

  • 构建beego项目

bee 工具是一个为了协助快速开发 beego 项目而创建的项目,通过 bee 您可以很容易的进行 beego 项目的创建、热编译、开发、测试、和部署。

$ bee new beegoProject
$ cd beegoProject
$ bee run

使用 bee new 命令新建一个名为“beegoProject”的项目文件。

bee new

切换至 beegoProject 项目文件夹,可以观察到它的项目树结构如下显示:

ls beegoProject

然后用cd命令切换至文件夹,最后用 bee run 初始化文件夹;如果输出以下信息,证明 beegoProject 项目文件已被初始化成功。

bee run

根据输出信息,返回一个URL:http://127.0.0.1:8080 ,在浏览器打开这个地址,如果能打开这个画面,就证明整个 beego 框架搭建教程就到此结束了!

beego web

学习路线

附:beego 学习路线规划
路线


文章来源:智云一二三科技

文章标题:Golang 框架学习:搭建beego

文章地址:https://www.zhihuclub.com/3888.shtml

关于作者: 智云科技

热门文章

评论已关闭

135条评论

  1. Hello there, just became alert to your blog through Google, and found that it is truly informative. Stafani Hoyt Horne

  2. Hi there mates, its wonderful post about educationand entirely defined, keep it up all the time. Cindi Roberto Obau

  3. Din nou scribd.com nu-mi permite afisarea documentelor incarcate pe acest site. Arabela Bond Etta

  4. I really like your writing style, excellent info, regards for posting :D. Catherin Zachary Mable

  5. If you learn how to take a hit, you will be able to absorb the impact and protect yourself from any injuries. Hillary Derron Mungo

  6. Wow! This can be one particular of the most beneficial blogs We have ever arrive across on this subject. Actually Magnificent. I am also a specialist in this topic so I can understand your hard work. Corny Ellswerth Gebhardt

  7. Keep up the excellent work , I read few articles on this website and I believe that your site is rattling interesting and has got sets of fantastic info . Gerianna Felipe Casey

  8. I enjoy looking through an article that will make men and women think. Also, thanks for allowing for me to comment! Isadora Wells Stoecker

  9. Sit amet velit metus. Proin posuere, ligula nec porttitor eget luctus, risus lectus tristique ligula, quis vivam pretium elit diam a nisi. Proin vehicula malesuada dolor, vel rutrum. quam sollicitudin. Jojo Claiborne Allsopp

  10. Well I really enjoyed studying it. This information offered by you is very useful for good planning. Beverie Hakim Randell

  11. Excellent blog here! Additionally your web site a lot up fast! What host are you using? Can I get your associate link in your host? I desire my website loaded up as fast as yours lol Rubia Worthington Mellie

  12. Very nice article. I definitely appreciate this website. Stick with it! Eddie Wilbert Ignazio

  13. Wow, a splendidly created blog, dealing with all elements of the subject as well as the writing style is impressive. Your blog site not merely happy me however also surprised me that there are actually still great writers at blogging sites who adhere to real parts of creating. Typically folks center either on creating style or content information but you have actually fully dealt with both parts in details. II found your blog as an outstanding one in my entire time of reading. I additionally create blog sites to provide my adventure and also expertise with accurate visitors. Below is my blog post concerning the most effective cars and truck servicing as well as Maserati repair work Dubai. Read my blog site as well as let me understand about your customer review. Carin Thorvald Willey

  14. Thank you for sharing your thoughts. I really appreciate your efforts and I am waiting for your further write ups thank you once again. Gerty Everett Noleta

  15. Thanks for a marvelous posting! I certainly enjoyed reading it, you are a great author. I will always bookmark your blog and may come back sometime soon. I want to encourage you to continue your great posts, have a nice evening! Bev Erv Kooima

  16. Have you ever thought about creating an ebook or guest authoring on other blogs? I have a blog based upon on the same topics you discuss and would love to have you share some stories/information. I know my readers would appreciate your work. If you are even remotely interested, feel free to send me an email. Pansy Cecilius Venu

  17. Hey, I think your site might be having browser compatibility issues. When I look at your website in Chrome, it looks fine but when opening in Internet Explorer, it has some overlapping. I just wanted to give you a quick heads up! Other then that, very good blog!| Tammi Connie Andi

  18. Amen to turning the media off for bit. And that Mr. Bean GIF put me in just the right mood to get going! Brandea Maximilien Marte

  19. An additional issue is that video games are usually serious as the name indicated with the major focus on understanding rather than leisure. Although, it comes with an entertainment facet to keep children engaged, each one game is usually designed to focus on a specific group of skills or program, such as numbers or science. Thanks for your posting. Demeter Luciano Maybelle

  20. Having read this I believed it was very informative. I appreciate you finding the time and energy to put this short article together. I once again find myself spending way too much time both reading and posting comments. But so what, it was still worthwhile! Emlynne Frans Noby

  21. magnificent points altogether, you simply gained a new reader. What may you suggest about your post that you just made a few days ago? Any positive?| Libbey ErvIn Camm

  22. But it is important is usually to pick something which is comfortable to wear. Diena Haley Verlie

  23. Excellent post! Loved the insight I got from this. Also dialling in time management and the 5am club.. the work that can be done is incredible. Betteann Trefor Goat

  24. It was a excitement getting to your sitea short while ago. I came here at the current timehoping to discover interesting things. And I was not let down. Your ideas on new tactics on this subject material were helpful and an first-class help to my family members. Thank you for creating time to write out these things because wellbecause for sharing your thinking. Theodosia Lance Gaskill

  25. Are countries allowed to record more than once and choose the best recording? Donni Langsdon Roderigo

  26. ankara nakliyat, evden eve nakliyat, sehirler arasi nakliyat, sehir ici nakliyat

  27. SMM, kendinizi veya şirketinizi tanıtmak için Instagram, Facebook, Twitter, Youtube ve daha pek çok sosyal medya platformunun kullanılmasıdır. Çevrimiçi varlığınızı artırmanın bir yolunu arıyorsanız, en iyi ve en ucuz fiyatlarla panelimizi kullanabilirsiniz.

  28. The men scrutinised her then started to pull at her clothing. Their foreign words were lost on her but she recognised lust in their eyes. She was pinned to the ground then one of the men kneeled between her legs whilst the other two held her arms apart. The man starter to remove the armor around his groin. She struggled and yelled again breaking one hand free until the other man drew a dagger and placed it at her neck. She froze with the words of father running through her mind �survive at all costs, there nothing you can do dead�.

  29. Ok her tits, they were big and round, I don�t know what size they were, but I could cup them in my hands, squeeze them together and tit fuck her all night long. Then there was her nipples, oh sweet nipples, they fit prefect around my lips and in my mouth.

  30. PDF kitap indir, ücretsiz PDF kitapları indirme sitesi. İnternette arayıp bulamadığınız tüm PDF kitaplar burada. Ücretsiz Pdf Kitap indir ve Oku. Yandex Disk E Kitap Arşivi İndirme Sitesi! Ücretsiz PDF formatında e-kitap indirebileceğiniz paylaşım sitesi. inlerce PDF Kitap indir içeriğini, EPUB Kitap ve PDF Kitap formatlarıyla sitemizde bulabilirsiniz! Dilediğiniz kitabı ücretsiz bir şekilde okuyabilirsiniz.

  31. PDF kitap indir, ücretsiz PDF kitapları indirme sitesi. İnternette arayıp bulamadığınız tüm PDF kitaplar burada. Ücretsiz Pdf Kitap indir ve Oku. Yandex Disk E Kitap Arşivi İndirme Sitesi! Ücretsiz PDF formatında e-kitap indirebileceğiniz paylaşım sitesi. inlerce PDF Kitap indir içeriğini, EPUB Kitap ve PDF Kitap formatlarıyla sitemizde bulabilirsiniz! Dilediğiniz kitabı ücretsiz bir şekilde okuyabilirsiniz.

  32. Yes, this is a good post without any doubts. You really doing a great Job. I inspired from you. So keep it up!

  33. Aenean lectus elit, fermentum non, convallis id, sagittis at, neque. Nullam mauris orci, aliquet et, iaculis et, viverra vitae, ligula. Nulla ut felis in purus aliquam imperdiet. Maecenas aliquet mollis lectus

  34. Attractive component of content. I simply stumbled upon your website and in accession capital to say that I get in fact loved account your blog posts.Ken Park

  35. I am actually happy to read this weblog posts which consists of tons of helpful facts, thanks for providing these kinds of information.

  36. I have been searching all over a post about that for quite a long time. Thanks for publishing this great content without doubts is very useful. I absolutely love your blog. Excellent colors

  37. Wow, that’s what I was looking for, what a information! present here at this
    blog, thanks admin of this site.

  38. Wow, that’s what I was looking for, what a information! present here at this
    blog, thanks admin of this site.

  39. wonderful post, very informative. I’m wondering why the opposite specialists of this sector don’t realize this.
    You should continue your writing. I am confident, you’ve a great readers’ base
    already!

  40. I can see you understand my problem. Some person would find my best friend attractive, don�t you think so? Stroking her arm again softly.

  41. Thanks for this article. I might also like to express that it can end up being hard when you find yourself in school and simply starting out to create a long credit rating. There are many scholars who are just trying to endure and have long or favourable credit history can occasionally be a difficult point to have.

  42. hey there and thanks on your info ? I have definitely picked up something new from right here. I did then again expertise some technical issues the use of this website, as I skilled to reload the site lots of instances previous to I may get it to load properly. I have been considering in case your web hosting is OK? Now not that I’m complaining, however sluggish loading circumstances times will sometimes affect your placement in google and can damage your high quality rating if ads and ***********|advertising|advertising|advertising and *********** with Adwords. Well I?m including this RSS to my email and can look out for a lot extra of your respective exciting content. Ensure that you replace this again soon..

  43. شركة نقل عفش من جدة إلى تونس, شركة شحن إلى تونس , أسعار الشحن من السعودية إلى تونس , شركة شحن من جدة إلى اتونس说道:

    I?d have to test with you here. Which isn’t one thing I usually do! I take pleasure in reading a publish that may make people think. Also, thanks for allowing me to remark!

  44. I would also like to add that if you do not surely have an insurance policy or you do not participate in any group insurance, you could possibly well make use of seeking the aid of a health broker. Self-employed or those that have medical conditions generally seek the help of an health insurance brokerage service. Thanks for your short article.

  45. PDF kitap indir, ücretsiz PDF kitapları indirme sitesi. İnternette arayıp bulamadığınız tüm PDF kitaplar burada. Ücretsiz Pdf Kitap indir ve Oku. Yandex Disk E Kitap Arşivi İndirme Sitesi! Ücretsiz PDF formatında e-kitap indirebileceğiniz paylaşım sitesi. inlerce PDF Kitap indir içeriğini, EPUB Kitap ve PDF Kitap formatlarıyla sitemizde bulabilirsiniz! Dilediğiniz kitabı ücretsiz bir şekilde okuyabilirsiniz.

  46. Malta Barber for impeccable men’s haircuts and grooming experiences. Our expert barbers skillfully blend modern and traditional techniques to craft unique looks that suit every individual’s style. Using carefully selected products and specialized grooming tools, we ensure a flawless shaving experience.

网站地图