Use of go-web framework-beego

foreword

The beego framework was developed in 2012 and is open sourced by a Chinese bigwig in order to provide an efficient web application development framework.

github address:github.com/beego/beegoSo far, 28.5k stars have been harvested.

Official website address:beego.vip/

It can be seen that this framework is very important. Compared with go developers, it is a good choice to quickly build a set of web applications.

develop

beego installation

On the premise that the computer has installed the go environment, check the local computer go versiongo version

go get github.com/beego/beego/v2

image.png

bee installation

The bee tool is a project created to assist the rapid development of beego projects. Through bee, you can easily create, hot compile, develop, test, and deploy beego projects.

Versions prior to go 1.16go get -u github.com/beego/bee/v2

go 1.16 and latergo install github.com/beego/bee/v2@latest

image.png

Verify that the installation of bee was successful

image.png

New Project

In the root directory src of go, execute and bee new beegodemo image.pngyou can see the following, create a new beegodemo project file, open this folder with golang to see the directory structure

image.pngIt can be guessed that main.go must be the entry file. Before running, remember to go mod vendordownload all dependencies first.

image.png

run the project

package main

import (
   _ "beegodemo/routers"
   beego "github.com/beego/beego/v2/server/web"
)

func main() {
   beego.Run()
}

Open the main.go file, you can see that there is only one line of code in the main method, and our service can be started.

runbee run

image.png

image.png

problem log

Most of the main problems encountered are environmental problems

go tool: no such tool compile

If this is prompted after bee run, probably the go version environment does not have this compile tool, you can go to the go version directory to view

image.pngConfirm the go version of the current environment, there is this compile in the directory. learn to use

go versionCurrently installed go version

go envView go configuration

cat  ~/.zshrcView environment variables under mac

If there is a problem with running and compiling, first compare the configuration of each environment variable.

Summarize

The beego project was successfully built for the first time, and other development needs to be done in the future, that is, it can be carried out according to the official documents. The various web frameworks of go are still very good, and there are others

Buffalo:gobuffalo.io/

Echo:github.com/labstack/ec…

Gin: An HTTP web framework written in Go. It provides a Martini-style API with better performance.github.com/gin-gonic/g…

Iris: Currently the fastest growing Go web framework. Provides full MVC functionality and is future-proof.

www.iris-go.com/

Revel: A high productivity, full stack Go web framework.
github.com/revel/revel

This article is participatingTechnical Special Issue 18 - Talking about the Go Language Framework

Guess you like

Origin juejin.im/post/7121536082151211022