aliyunfcgoruntime

package module
v0.0.0-...-9016629 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2021 License: MIT Imports: 7 Imported by: 0

README

Aliyun fc go runtime

阿里云函数计算 golang custom runtime 框架。

Install

go get github.com/Tarocch1/aliyun-fc-go-runtime

Event Function

package main

import (
	"fmt"

	gr "github.com/Tarocch1/aliyun-fc-go-runtime"
)

func initialize(ctx *gr.FCContext) error {
	fmt.Println("init golang!")
	return nil
}

func invoke(ctx *gr.FCContext, event []byte) ([]byte, error) {
	fmt.Println(fmt.Sprintf("hello golang!\ncontext = %+v", ctx))
	return event, nil
}

func main() {
	handler := &gr.Handler{
		Initialize: initialize,
		Invoke:     invoke,
	}
	gr.Start(handler)
}

HTTP Function

package main

import (
	"fmt"
	"net/http"

	gr "github.com/Tarocch1/aliyun-fc-go-runtime"
)

func initialize(ctx *gr.FCContext) error {
	fmt.Println("init golang!")
	return nil
}

func httpInvoke(ctx *gr.FCContext, w http.ResponseWriter) error {
	w.Write([]byte(fmt.Sprintf("hello golang!\ncontext = %+v", ctx)))
	return nil
}

func main() {
	handler := &gr.Handler{
		Initialize: initialize,
		HttpInvoke: httpInvoke,
	}
	gr.Start(handler)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Start

func Start(h *Handler)

Types

type Credentials

type Credentials struct {
	AccessKeyID     string
	AccessKeySecret string
	SecurityToken   string
}

type FCContext

type FCContext struct {
	RequestID   string
	Credentials Credentials
	Function    FunctionMeta
	Service     ServiceMeta
	Region      string
	AccountID   string
	RetryCount  int
	Req         *http.Request
}

func NewFromContext

func NewFromContext(req *http.Request) *FCContext

type FunctionMeta

type FunctionMeta struct {
	Name                  string
	Handler               string
	Memory                int
	Timeout               int
	Initializer           string
	InitializationTimeout int
}

type Handler

type Handler struct {
	Initialize func(ctx *FCContext) error
	Invoke     func(ctx *FCContext, event []byte) ([]byte, error)
	HttpInvoke func(ctx *FCContext, w http.ResponseWriter) error
	Prefreeze  func(ctx *FCContext) error
	Prestop    func(ctx *FCContext) error
}

type ServiceMeta

type ServiceMeta struct {
	ServiceName string
	LogProject  string
	LogStore    string
	Qualifier   string
	VersionID   string
}

Jump to

Keyboard shortcuts

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