ipaas-component-go-sdk

module
v1.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 27, 2023 License: Apache-2.0

README

clickpaas Golang 组件SDK

基本介绍

本项目是clickpaas ipaas 组件 Golang 运行时的 SDK,包括使用 Golang 语言开发函数计算程序的依赖库、示例代码等。

快速开始

package main

import (
	"fmt"
	"gitee.com/clickpaas-ipaas-open/ipaas-component-go-sdk/common"
	"gitee.com/clickpaas-ipaas-open/ipaas-component-go-sdk/component"
)

//数据最终按照json格式传输,请参考json格式数据
type Config struct {
	Name string `json:"name"`
}
type Input struct {
	Code string `json:"code"`
}

type Output struct {
	Result string `json:"result"`
}

//Execute 简单的函数执行方法,不包含事务
//config 对应组件配置
//input 对应组件输入
//ctx 组件执行上下文信息
func Execute(config Config, input Input, ctx common.Context) (Output, error) {

	fmt.Printf("event: %v\n", config.Name)
	fmt.Println("hello world! 你好,世界!")
	ctx.Logger.Info("测试")
	return Output{
		Result: "123",
	}, nil
}

func main() {
	component.StartExecute(Execute)
}

编译打包

Golang 语言不支持在线编辑,仅支持 .zip 方式,可以直接上传也可以指定oss路径。

1. 在 Mac 或 Linux 下编译打包
  1. 下载函数计算 golang sdk 库:
go get gitee.com/clickpaas-ipaas-open/ipaas-component-go-sdk/component
  1. 编译并打包
GOOS=linux CGO_ENABLED=0 go build -o main main.go
zip component.zip main

设置GOOS=linux,确保编译后的可执行文件与函数计算平台的Go运行系统环境兼容,尤其是在非Linux环境中编译时。

补充说明如下:

  • 针对Linux操作系统,建议使用纯静态编译,配置CGO_ENABLED=0,确保可执行文件不依赖任何外部依赖库(如libc库),避免出现编译环境和Go运行时环境依赖库的兼容问题。示例如下:

    GOOS=linux CGO_ENABLED=0 go build -o main main.go
    
  • 针对M1 macOS(或其他ARM架构的机器),配置GOARCH=amd64,实现跨平台编译,示例如下:

    GOOS=linux GOARCH=amd64 go build -o main main.go
    
  • 如果你的包里有多个文件

    GOOS=linux go build main
    

部署

目前支持ipaas 平台代码包上传方式部署

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL