{"id":18918431,"url":"https://github.com/serverlessplus/go","last_synced_at":"2025-04-15T10:32:47.429Z","repository":{"id":57502475,"uuid":"182353929","full_name":"serverlessplus/go","owner":"serverlessplus","description":"serverless your go web apps","archived":false,"fork":false,"pushed_at":"2019-04-24T14:44:25.000Z","size":18,"stargazers_count":16,"open_issues_count":1,"forks_count":1,"subscribers_count":0,"default_branch":"master","last_synced_at":"2024-07-25T12:01:37.897Z","etag":null,"topics":["apigateway","beego","go-gin","scf","serverless","tencent-cloud"],"latest_commit_sha":null,"homepage":"http://serverless.plus","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/serverlessplus.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-04-20T03:14:31.000Z","updated_at":"2023-12-02T23:44:40.000Z","dependencies_parsed_at":"2022-09-13T08:20:17.601Z","dependency_job_id":null,"html_url":"https://github.com/serverlessplus/go","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serverlessplus%2Fgo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serverlessplus%2Fgo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serverlessplus%2Fgo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serverlessplus%2Fgo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/serverlessplus","download_url":"https://codeload.github.com/serverlessplus/go/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223668707,"owners_count":17182968,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["apigateway","beego","go-gin","scf","serverless","tencent-cloud"],"created_at":"2024-11-08T10:31:53.512Z","updated_at":"2024-11-08T10:32:21.081Z","avatar_url":"https://github.com/serverlessplus.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"![](serverless+.png)\n\n# Serverless + Go\n\n## 简介\n\n`serverlessplus` 是一个简单易用的工具，它可以帮助你将现有的 `beego` / `go gin` 等框架构建的应用借助 [API 网关](https://cloud.tencent.com/product/apigateway) 迁移到 [腾讯云无服务云函数](https://cloud.tencent.com/product/scf)（Tencent Cloud Serverless Cloud Function）上。\n\n## 开始使用\n\n```shell\n$ go get github.com/serverlessplus/go\n```\n\n假设有如下 `go gin` 应用：\n```go\npackage main\n\nimport \"github.com/gin-gonic/gin\"\n\nfunc main() {\n\tr := gin.Default()\n\tr.GET(\"/go-gin-example\", func(c *gin.Context) {\n\t\tc.Data(200, \"text/html\", []byte(\"hello world\"))\n\t})\n\tr.Run()\n}\n```\n\n进行如下简单修改, 即可迁移到[腾讯云无服务云函数](https://cloud.tencent.com/product/scf)（Tencent Cloud Serverless Cloud Function）上\n- 指定 `HTTP` 服务监听的端口\n- 将 `r.Run` 替换为 `net.Listen` 和 `http.Serve`\n- 初始化 `Handler`, 指定端口及需要进行 `base64` 编码的 `MIME` 类型\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\t\"net\"\n\t\"net/http\"\n\n\t\"github.com/gin-gonic/gin\"\n\tserverlessplus \"github.com/serverlessplus/go\"\n\t\"github.com/tencentyun/scf-go-lib/cloudfunction\"\n)\n\nconst (\n\tport = 1216\n)\n\nvar handler *serverlessplus.Handler\n\nfunc init() {\n\t// start your server\n\tr := gin.Default()\n\tr.GET(\"/go-gin-example\", func(c *gin.Context) {\n\t\tc.Data(200, \"text/html\", []byte(\"hello world\"))\n\t})\n\tl, err := net.Listen(\"tcp\", fmt.Sprintf(\"%s:%d\", serverlessplus.Host, port))\n\tif err != nil {\n\t\tfmt.Printf(\"failed to listen on port %d: %v\\n\", port, err)\n\t\t// panic to force the runtime to restart\n\t\tpanic(err)\n\t}\n\tgo http.Serve(l, r)\n\n\t// setup handler\n\ttypes := []string{\"image/png\"}\n\thandler = serverlessplus.NewHandler(port).WithBinaryMIMETypes(types)\n}\n\nfunc entry(ctx context.Context, req *serverlessplus.APIGatewayRequest) (*serverlessplus.APIGatewayResponse, error) {\n\treturn handler.Handle(ctx, req)\n}\n\nfunc main() {\n\tcloudfunction.Start(entry)\n}\n```\n\n## 示例\n\n- [go gin 示例](https://github.com/serverlessplus/go-gin-example)\n- [beego 示例](https://github.com/serverlessplus/beego-example)\n\n## 支持的框架\n\n`serverlessplus` 被设计为 `HTTP` 协议与框架进行交互, 对框架并没有限制\n\n## 路线图\n\n`serverlessplus` 处于活跃开发中，`API` 可能在未来的版本中发生变更，我们十分欢迎来自社区的贡献，你可以通过 pull request 或者 issue 来参与。\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fserverlessplus%2Fgo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fserverlessplus%2Fgo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fserverlessplus%2Fgo/lists"}