本文整理匯總了Golang中github.com/apex/apex/project.Project.FunctionByName方法的典型用法代碼示例。如果您正苦於以下問題:Golang Project.FunctionByName方法的具體用法?Golang Project.FunctionByName怎麽用?Golang Project.FunctionByName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/apex/apex/project.Project
的用法示例。
在下文中一共展示了Project.FunctionByName方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: rollback
// rollback the function with optional version.
func rollback(project *project.Project, name []string, version interface{}) {
fn, err := project.FunctionByName(name[0])
if err != nil {
log.Fatalf("error: %s", err)
}
if version == nil {
err = fn.Rollback()
} else {
err = fn.RollbackVersion(version.(string))
}
if err != nil {
log.Fatalf("error: %s", err)
}
}
示例2: build
// build outputs the generated archive to stdout.
func build(project *project.Project, name []string) {
fn, err := project.FunctionByName(name[0])
if err != nil {
log.Fatalf("error: %s", err)
}
zip, err := fn.Zip()
if err != nil {
log.Fatalf("error: %s", err)
}
_, err = io.Copy(os.Stdout, zip)
if err != nil {
log.Fatalf("error: %s", err)
}
}
示例3: invoke
// invoke reads request json from stdin and outputs the responses.
func invoke(project *project.Project, name []string, verbose, async bool) {
dec := json.NewDecoder(os.Stdin)
kind := function.RequestResponse
if async {
kind = function.Event
}
fn, err := project.FunctionByName(name[0])
if err != nil {
log.Fatalf("error: %s", err)
}
for {
var v struct {
Event interface{}
Context interface{}
}
err := dec.Decode(&v)
if err == io.EOF {
break
}
if err != nil {
log.Fatalf("error: %s", err)
}
reply, logs, err := fn.Invoke(v.Event, v.Context, kind)
if err != nil {
log.Fatalf("error: %s", err)
}
// TODO(tj) rename flag to --with-logs or --logs
if verbose {
io.Copy(os.Stderr, logs)
}
io.Copy(os.Stdout, reply)
fmt.Fprintf(os.Stdout, "\n")
}
}