Skip to content

Commit 4080730

Browse files
author
定戎
committed
add golang, nodejs10, nodejs12 and python3.7 demo that support websocket
1 parent 6af1049 commit 4080730

File tree

40 files changed

+794
-12
lines changed

40 files changed

+794
-12
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
async function preInit(inputObj) {
2+
console.log(`\n ____ _ _ ___ _ _ _ _____ ____
3+
/ _ \\/ \\ / \\\\ \\/// \\ /\\/ \\ /| / // _\\
4+
| / \\|| | | | \\ / | | ||| |\\ || | __\\| /
5+
| |-||| |_/\\| | / / | \\_/|| | \\|| | | | \\__
6+
\\_/ \\|\\____/\\_//_/ \\____/\\_/ \\| \\_/ \\____/`)
7+
}
8+
9+
async function postInit(inputObj) {
10+
console.log(`\n Welcome to the Aliyun FC start application
11+
This application requires to open these services:
12+
FC : https://fc.console.aliyun.com/
13+
14+
* 额外说明:s.yaml中声明了actions:
15+
部署前执行:make build
16+
如果不需要每次都构建项目,或者部署前不需要构建,或者已经手动构建了,可以注释掉这部分内容
17+
* 项目初始化完成,您可以直接进入项目目录下,并使用 s deploy 进行项目部署
18+
\n`)
19+
}
20+
21+
module.exports = {
22+
postInit,
23+
preInit
24+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Type: Application
2+
Name: fc-custom-golang-websocket
3+
Provider:
4+
- 阿里云
5+
Version: 0.0.3
6+
Description: 快速部署一个基于custom runtime 的 Golang WebSocket 类型的 Echo 函数到阿里云函数计算
7+
HomePage: https://github.com/devsapp/start-fc
8+
Tags:
9+
- 函数计算
10+
- 你好世界
11+
- 新手入门
12+
Category: 新手入门
13+
Service:
14+
函数计算:
15+
Authorities:
16+
- 创建函数
17+
- 删除函数
18+
- 创建服务
19+
- 删除服务
20+
Runtime: custom
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# 阿里云函数计算 Custom Golang WebSocket 函数案例
2+
3+
只需几步就可以快速在阿里云函数计算服务上体验一键部署一个 Golang 应用:
4+
5+
- 初始化项目:`s init fc-custom-golang-websocket -d fc-custom-golang-websocket`
6+
- 进入项目:`cd fc-custom-golang-websocket`
7+
- 部署项目:`s deploy -y`
8+
- 调用函数:`# 使用浏览器或者 Postman 进行调用`
9+
10+
即可实现`Custom Golang` WebSocket 函数案例的初始化、部署整个流程。
11+
12+
> 本应用仓库地址:https://github.com/devsapp/start-fc
13+
14+
------------------------------------
15+
> # More
16+
> 欢迎您使用阿里云函数计算 FC 组件进行项目开发
17+
> 组件仓库地址/帮助文档:https://github.com/devsapp/fc
18+
> Yaml参考文档:https://github.com/devsapp/fc/blob/main/docs/zh/yaml.md
19+
> 快速入门:
20+
> - 快速创建应用:https://github.com/devsapp/fc/blob/main/docs/zh/quick_start_application.md
21+
> - 快速使用命令:https://github.com/devsapp/fc/blob/main/docs/zh/quick_start_function.md
22+
------------------------------------
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Alibaba Cloud Function Computing Custom Golang WebSocket function
2+
3+
You can quickly experience one-click deployment of a Golang application on Alibaba Cloud Function Computing Service in just a few steps:
4+
5+
- Initialize the project: `s init fc-custom-golang-websocket -d fc-custom-golang-websocket`
6+
- Enter the project: `cd fc-custom-golang-websocket`
7+
- Deployment project: `s deploy -y`
8+
- Invoke function: `# invoke by browser or postman`
9+
10+
> This application warehouse address: https://github.com/devsapp/start-fc
11+
12+
------------------------------------
13+
> # More
14+
> Welcome to use Alibaba Cloud Function Compute FC component for project development
15+
>
16+
> Component warehouse address/help document: https://github.com/devsapp/fc
17+
>
18+
> Yaml reference documentation: https://github.com/devsapp/fc/blob/main/docs/zh/yaml.md
19+
>
20+
> Quick start:
21+
> - Quickly create an application: https://github.com/devsapp/fc/blob/main/docs/zh/quick_start_application.md
22+
> - Quick use of commands: https://github.com/devsapp/fc/blob/main/docs/zh/quick_start_function.md
23+
------------------------------------
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
build-img:
2+
docker build -t fc-go-runtime -f build-image/Dockerfile build-image
3+
4+
build: build-img
5+
docker run --rm -it -v $$(pwd):/tmp fc-go-runtime bash -c "GOARCH=amd64 go build -o /tmp/code//bootstrap /tmp/code/main.go"
6+
chmod +x code/bootstrap
7+
8+
deploy: build
9+
s deploy -y
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
FROM golang:1.12.16-stretch
2+
RUN mkdir -p $GOPATH/src/golang.org/x/
3+
RUN cd $GOPATH/src/golang.org/x/ && git clone https://github.com/golang/net.git
4+
RUN cd $GOPATH/src/golang.org/x/ && git clone https://github.com/golang/sys.git
5+
RUN go get github.com/awesome-fc/golang-runtime
6+
RUN go get github.com/gorilla/websocket
Binary file not shown.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package main
2+
3+
import (
4+
"net/http"
5+
6+
"github.com/gorilla/websocket"
7+
)
8+
9+
var upgrader = websocket.Upgrader{}
10+
11+
func echo(w http.ResponseWriter, r *http.Request) {
12+
c, err := upgrader.Upgrade(w, r, nil)
13+
if err != nil {
14+
return
15+
}
16+
defer c.Close()
17+
for {
18+
mt, message, err := c.ReadMessage()
19+
if err != nil {
20+
break
21+
}
22+
err = c.WriteMessage(mt, message)
23+
if err != nil {
24+
break
25+
}
26+
}
27+
}
28+
29+
func main() {
30+
http.HandleFunc("/", echo)
31+
http.ListenAndServe(":9000", nil)
32+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* /*
3+
* To enable the initializer feature (https://help.aliyun.com/document_detail/156876.html)
4+
* please implement the initializer function as below:
5+
* exports.initializer = (context, callback) => {
6+
* console.log('initializing');
7+
* callback(null, '');
8+
* };
9+
*
10+
* @format
11+
*/
12+
13+
exports.handler = (event, context, callback) => {
14+
console.log('hello world');
15+
callback(null, 'hello world');
16+
};
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# 阿里云函数计算 Custom Golang WebSocket 函数案例
2+
3+
只需几步就可以快速在阿里云函数计算服务上体验一键部署一个 Golang WebSocket 应用:
4+
5+
- 初始化项目:`s init fc-custom-golang-websocket -d fc-custom-golang-websocket`
6+
- 进入项目:`cd fc-custom-golang-websocket`
7+
- 部署项目:`s deploy -y`
8+
- 调用函数:`# 在浏览器中或者 Postman 中进行调用`
9+
10+
即可实现`Custom Golang` WebSocket 函数案例的初始化、部署整个流程。
11+
12+
> 本应用仓库地址:https://github.com/devsapp/start-fc
13+
14+
------------------------------------
15+
> # More
16+
> 欢迎您使用阿里云函数计算 FC 组件进行项目开发
17+
> 组件仓库地址/帮助文档:https://github.com/devsapp/fc
18+
> Yaml参考文档:https://github.com/devsapp/fc/blob/main/docs/zh/yaml.md
19+
> 快速入门:
20+
> - 快速创建应用:https://github.com/devsapp/fc/blob/main/docs/zh/quick_start_application.md
21+
> - 快速使用命令:https://github.com/devsapp/fc/blob/main/docs/zh/quick_start_function.md
22+
------------------------------------

0 commit comments

Comments
 (0)