Skip to content

Commit

Permalink
Merge pull request #19 from devsapp/add-golang
Browse files Browse the repository at this point in the history
add hello world case in golang runtime
  • Loading branch information
rsonghuster authored Feb 25, 2022
2 parents 40e22cd + 1de2d8a commit b716bd9
Show file tree
Hide file tree
Showing 14 changed files with 316 additions and 1 deletion.
20 changes: 20 additions & 0 deletions event-function/fc-event-golang1.x/publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Type: Application
Name: start-fc-event-golang1.x
Version: 0.0.1
Provider:
- 阿里云
Description: 快速部署一个 golang1.x 的 Event 类型的 Hello World 函数到阿里云函数计算。
HomePage: https://github.com/devsapp/start-fc
Tags:
- 函数计算
- 你好世界
- 新手入门
Category: 新手入门
Service:
函数计算:
Authorities:
- 创建函数
- 删除函数
- 创建服务
- 删除服务
Runtime: Golang
23 changes: 23 additions & 0 deletions event-function/fc-event-golang1.x/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# 阿里云函数计算 Golang 1.x 案例

只需几步就可以快速在阿里云函数计算服务上体验 Golang 1.x :

- 初始化项目:`s init start-fc-event-golang1.x`
- 进入项目:`cd start-fc-event-golang1.x`
- 部署项目:`s deploy`
- 触发项目:`s invoke -e "{}"`

即可实现`Golang 1.x`案例的初始化、部署整个流程。

> 本应用仓库地址:https://github.com/devsapp/start-fc
------------------------------------
> # More
> 欢迎您使用阿里云函数计算 FC 组件进行项目开发
> 组件仓库地址/帮助文档:https://github.com/devsapp/fc
> Yaml参考文档:https://github.com/devsapp/fc/blob/main/docs/zh/yaml.md
> 快速入门:
> - 快速创建应用:https://github.com/devsapp/fc/blob/main/docs/zh/quick_start_application.md
> - 快速使用命令:https://github.com/devsapp/fc/blob/main/docs/zh/quick_start_function.md
------------------------------------

23 changes: 23 additions & 0 deletions event-function/fc-event-golang1.x/src/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# 阿里云函数计算 Golang 1.x 案例

只需几步就可以快速在阿里云函数计算服务上体验 Golang 1.x :

- 初始化项目:`s init start-fc-event-golang1.x`
- 进入项目:`cd start-fc-event-golang1.x`
- 部署项目:`s deploy`
- 触发项目:`s invoke -e "{}"`

即可实现`Golang 1.x`案例的初始化、部署整个流程。

> 本应用仓库地址:https://github.com/devsapp/start-fc
------------------------------------
> # More
> 欢迎您使用阿里云函数计算 FC 组件进行项目开发
> 组件仓库地址/帮助文档:https://github.com/devsapp/fc
> Yaml参考文档:https://github.com/devsapp/fc/blob/main/docs/zh/yaml.md
> 快速入门:
> - 快速创建应用:https://github.com/devsapp/fc/blob/main/docs/zh/quick_start_application.md
> - 快速使用命令:https://github.com/devsapp/fc/blob/main/docs/zh/quick_start_function.md
------------------------------------

25 changes: 25 additions & 0 deletions event-function/fc-event-golang1.x/src/code/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package main

import (
"fmt"

"github.com/aliyun/fc-runtime-go-sdk/fc"
)

func main() {
fc.Start(HandleRequest)
}

/*
event:
{
"key1": "value1",
"key2": "value2",
"key3": "value3"
}
*/
func HandleRequest(event map[string]interface{}) (string, error) {
fmt.Printf("event: %v\n", event)
fmt.Println("hello world! 你好,世界!")
return "hello world! 你好,世界!", nil
}
59 changes: 59 additions & 0 deletions event-function/fc-event-golang1.x/src/s.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# ------------------------------------
# 欢迎您使用阿里云函数计算 FC 组件进行项目开发
# 组件仓库地址/帮助文档:https://github.com/devsapp/fc
# Yaml参考文档:https://github.com/devsapp/fc/blob/jiangyu-docs/docs/zh/yaml.md
# 关于:
# - Serverless Devs和FC组件的关系、如何声明/部署多个函数、超过50M的代码包如何部署
# - 关于.fcignore使用方法、工具中.s目录是做什么、函数进行build操作之后如何处理build的产物
# 等问题,可以参考文档:https://github.com/devsapp/fc/blob/jiangyu-docs/docs/zh/tips.md
# 关于如何做CICD等问题,可以参考:https://github.com/Serverless-Devs/Serverless-Devs/blob/master/docs/zh/cicd.md
# 有问题快来钉钉群问一下吧:33947367
# ------------------------------------

edition: 1.0.0
name: hello-world-app
access: "{{ access }}"

vars: # 全局变量
region: cn-hangzhou
service:
name: hello-world-service
description: 'hello world by serverless devs'

services:
helloworld: # 业务名称/模块名称
component: fc
actions: # 自定义执行逻辑
pre-deploy: # 在deploy之前运行
- run: GO111MODULE=on go get github.com/aliyun/fc-runtime-go-sdk
path: ./
- run: GOOS=linux CGO_ENABLED=0 go build -o target/main main.go # 要运行的命令行
path: ./code # 命令行运行的路径
# post-deploy: # 在deploy之后运行
# - run: s versions # 要运行的命令行
# path: ./ # 命令行运行的路径
props: # 组件的属性值
region: ${vars.region}
service: ${vars.service}
function:
name: event-go1
description: 'hello world by serverless devs'
runtime: go1
codeUri: ./code/target
handler: main
memorySize: 128
timeout: 60
# next-function: # 第二个函数的案例,仅供参考
# # 如果在当前项目下执行 s deploy,会同时部署模块:
# # helloworld:服务hello-world-service,函数cpp-event-function
# # next-function:服务hello-world-service,函数next-function-example
# # 如果想单独部署当前服务与函数,可以执行 s + 模块名/业务名 + deploy,例如:s next-function deploy
# # 如果想单独部署当前函数,可以执行 s + 模块名/业务名 + deploy function,例如:s next-function deploy function
# # 更多命令可参考:https://github.com/devsapp/fc/tree/jiangyu-docs/docs#文档相关
# component: fc
# props:
# region: ${vars.region}
# service: ${vars.service} # 应用整体的服务配置
# function: # 定义一个新的函数
# name: next-function-example
# description: 'hello world by serverless devs'
1 change: 1 addition & 0 deletions event-function/fc-event-golang1.x/version.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- 新版本支持
20 changes: 20 additions & 0 deletions http-function/fc-http-golang1.x/publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Type: Application
Name: start-fc-http-golang1.x
Version: 0.0.1
Provider:
- 阿里云
Description: 快速部署一个 golang1.x 的 HTTP 类型的 Hello World 函数到阿里云函数计算。
HomePage: https://github.com/devsapp/start-fc
Tags:
- 函数计算
- 你好世界
- 新手入门
Category: 新手入门
Service:
函数计算:
Authorities:
- 创建函数
- 删除函数
- 创建服务
- 删除服务
Runtime: Golang
23 changes: 23 additions & 0 deletions http-function/fc-http-golang1.x/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# 阿里云函数计算 Golang 1.x 案例

只需几步就可以快速在阿里云函数计算服务上体验 Golang 1.x :

- 初始化项目:`s init start-fc-http-golang1.x`
- 进入项目:`cd start-fc-http-golang1.x`
- 部署项目:`s deploy`
- 触发项目:`s invoke -e "{}"`

即可实现`Golang 1.x`案例的初始化、部署整个流程。

> 本应用仓库地址:https://github.com/devsapp/start-fc
------------------------------------
> # More
> 欢迎您使用阿里云函数计算 FC 组件进行项目开发
> 组件仓库地址/帮助文档:https://github.com/devsapp/fc
> Yaml参考文档:https://github.com/devsapp/fc/blob/main/docs/zh/yaml.md
> 快速入门:
> - 快速创建应用:https://github.com/devsapp/fc/blob/main/docs/zh/quick_start_application.md
> - 快速使用命令:https://github.com/devsapp/fc/blob/main/docs/zh/quick_start_function.md
------------------------------------

23 changes: 23 additions & 0 deletions http-function/fc-http-golang1.x/src/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# 阿里云函数计算 Golang 1.x 案例

只需几步就可以快速在阿里云函数计算服务上体验 Golang 1.x :

- 初始化项目:`s init start-fc-http-golang1.x`
- 进入项目:`cd start-fc-http-golang1.x`
- 部署项目:`s deploy`
- 触发项目:`s invoke -e "{}"`

即可实现`Golang 1.x`案例的初始化、部署整个流程。

> 本应用仓库地址:https://github.com/devsapp/start-fc
------------------------------------
> # More
> 欢迎您使用阿里云函数计算 FC 组件进行项目开发
> 组件仓库地址/帮助文档:https://github.com/devsapp/fc
> Yaml参考文档:https://github.com/devsapp/fc/blob/main/docs/zh/yaml.md
> 快速入门:
> - 快速创建应用:https://github.com/devsapp/fc/blob/main/docs/zh/quick_start_application.md
> - 快速使用命令:https://github.com/devsapp/fc/blob/main/docs/zh/quick_start_function.md
------------------------------------

19 changes: 19 additions & 0 deletions http-function/fc-http-golang1.x/src/code/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package main

import (
"context"
"net/http"

"github.com/aliyun/fc-runtime-go-sdk/fc"
)

func main() {
fc.StartHttp(HandleHttpRequest)
}

func HandleHttpRequest(ctx context.Context, w http.ResponseWriter, req *http.Request) error {
w.WriteHeader(http.StatusOK)
w.Header().Add("Content-Type", "text/plain")
w.Write([]byte("hello, world!\n"))
return nil
}
75 changes: 75 additions & 0 deletions http-function/fc-http-golang1.x/src/s.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# ------------------------------------
# 欢迎您使用阿里云函数计算 FC 组件进行项目开发
# 组件仓库地址/帮助文档:https://github.com/devsapp/fc
# Yaml参考文档:https://github.com/devsapp/fc/blob/jiangyu-docs/docs/zh/yaml.md
# 关于:
# - Serverless Devs和FC组件的关系、如何声明/部署多个函数、超过50M的代码包如何部署
# - 关于.fcignore使用方法、工具中.s目录是做什么、函数进行build操作之后如何处理build的产物
# 等问题,可以参考文档:https://github.com/devsapp/fc/blob/jiangyu-docs/docs/zh/tips.md
# 关于如何做CICD等问题,可以参考:https://github.com/Serverless-Devs/Serverless-Devs/blob/master/docs/zh/cicd.md
# 有问题快来钉钉群问一下吧:33947367
# ------------------------------------

edition: 1.0.0
name: hello-world-app
access: "{{ access }}"

vars: # 全局变量
region: cn-hangzhou
service:
name: hello-world-service
description: 'hello world by serverless devs'

services:
helloworld: # 业务名称/模块名称
component: fc
actions: # 自定义执行逻辑
pre-deploy: # 在deploy之前运行
- run: GO111MODULE=on go get github.com/aliyun/fc-runtime-go-sdk
path: ./
- run: GOOS=linux CGO_ENABLED=0 go build -o target/main main.go # 要运行的命令行
path: ./code # 命令行运行的路径
# post-deploy: # 在deploy之后运行
# - run: s versions # 要运行的命令行
# path: ./ # 命令行运行的路径
props: # 组件的属性值
region: ${vars.region}
service: ${vars.service}
function:
name: http-go1
description: 'hello world by serverless devs'
runtime: go1
codeUri: ./code/target
handler: main
memorySize: 128
timeout: 60
triggers:
- name: httpTrigger
type: http
config:
authType: anonymous
methods:
- GET
- POST
customDomains:
- domainName: auto
protocol: HTTP
routeConfigs:
- path: /*
methods:
- GET
- POST
# next-function: # 第二个函数的案例,仅供参考
# # 如果在当前项目下执行 s deploy,会同时部署模块:
# # helloworld:服务hello-world-service,函数cpp-event-function
# # next-function:服务hello-world-service,函数next-function-example
# # 如果想单独部署当前服务与函数,可以执行 s + 模块名/业务名 + deploy,例如:s next-function deploy
# # 如果想单独部署当前函数,可以执行 s + 模块名/业务名 + deploy function,例如:s next-function deploy function
# # 更多命令可参考:https://github.com/devsapp/fc/tree/jiangyu-docs/docs#文档相关
# component: fc
# props:
# region: ${vars.region}
# service: ${vars.service} # 应用整体的服务配置
# function: # 定义一个新的函数
# name: next-function-example
# description: 'hello world by serverless devs'
1 change: 1 addition & 0 deletions http-function/fc-http-golang1.x/version.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- 新版本支持
2 changes: 2 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
- [fc-event-python2.7](event-function/fc-event-python2.7/src):`s init start-fc-event-python2`
- [fc-event-python3.6](event-function/fc-event-python3.6/src):`s init start-fc-event-python3`
- [fc-event-java8](event-function/fc-event-java8/src):`s init start-fc-event-java8`
- [fc-event-golang1.x](event-function/fc-event-java8/src):`s init start-fc-event-golang1.x`
- HTTP函数
- [fc-http-node.js6](http-function/fc-http-node.js6/src):`s init start-fc-http-nodejs6`
- [fc-http-node.js8](http-function/fc-http-node.js8/src):`s init start-fc-http-nodejs8`
Expand All @@ -30,6 +31,7 @@
- [fc-http-python2.7](http-function/fc-http-python2.7/src):`s init start-fc-http-python2`
- [fc-http-python3.6](http-function/fc-http-python3.6/src):`s init start-fc-http-python3`
- [fc-http-java8](http-function/fc-http-java8/src):`s init start-fc-http-java8`
- [fc-http-golang1.x](http-function/fc-http-java8/src):`s init start-fc-http-golang1.x`
- Custom案例(自定义运行时)
- Golang [fc-custom-golang-event](custom-function/golang/fc-custom-golang-event/src):`s init fc-custom-golang-event`
- Nodejs10 [fc-custom-nodejs10-event](custom-function/nodejs10/fc-custom-nodejs10-event/src):`s init fc-custom-nodejs10-event`
Expand Down
3 changes: 2 additions & 1 deletion update.list
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
http-function/fc-http-node.js14
event-function/fc-event-golang1.x
http-function/fc-http-golang1.x

0 comments on commit b716bd9

Please sign in to comment.