-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from devsapp/add-golang
add hello world case in golang runtime
- Loading branch information
Showing
14 changed files
with
316 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
------------------------------------ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
------------------------------------ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
- 新版本支持 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
------------------------------------ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
------------------------------------ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
- 新版本支持 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |