Go

Go - Web开发之Beego初探

2019-11-24  本文已影响0人  红薯爱帅

1. 前言

计算机软件经历了数十年的发展,形成了多种学术流派,有面向过程编程、面向对象编程、函数式编程、面向消息编程等,这些思想究竟孰优孰劣,众说纷纭。

除了OOP外,近年出现了一些小众的编程哲学,Go语言对这些思想亦有所吸收。例如,Go语言接受了函数式编程的一些想法,支持匿名函数与闭包。再如,Go语言接受了以Erlang语言为代表的面向消息编程思想,支持goroutine和通道,并推荐使用消息而不是共享内存来进行并发编程。总体来说,Go语言是一个非常现代化的语言,精小但非常强大。

Go 语言最主要的特性:

Web开发已成当今主流,Go开发社区已浮现了许多优秀的Web Framwork,本文通过3个sample简单介绍一下国人开发的Beego。
https://github.com/astaxie/beego

image.png

2. Beego安装

Download and install

go get github.com/astaxie/beego

Create file hello.go

package main

import "github.com/astaxie/beego"

func main(){
    beego.Run()
}

Build and run

go build hello.go
./hello

Go to http://localhost:8080

Congratulations! You've just built your first beego app.

3. Beego samples

WebIM - Chat room demo based on long polling and WebSocket.

image.png

Todo - todo app based on beego.angularJS with API which is designed by beego

image.png

shorturl - shouturl app based on beego. API applications

$ http :8080/v1/shorten/?longurl=http://google.com
HTTP/1.1 200 OK
Content-Length: 59
Content-Type: application/json; charset=utf-8
Date: Sun, 24 Nov 2019 14:21:21 GMT
Server: beegoServer:1.12.0

{
    "UrlLong": "http://google.com",
    "UrlShort": "5laZF"
}

$ http :8080/v1/expand/?shorturl=5laZF
HTTP/1.1 200 OK
Content-Length: 59
Content-Type: application/json; charset=utf-8
Date: Sun, 24 Nov 2019 14:21:50 GMT
Server: beegoServer:1.12.0

{
    "UrlLong": "http://google.com",
    "UrlShort": "5laZF"
}

4. Refers

上一篇 下一篇

猜你喜欢

热点阅读