当前位置: 首页 > news >正文

网站推广网络推广方附近的电脑培训班在哪里

网站推广网络推广方,附近的电脑培训班在哪里,郑州建设信息网网,做仿站如何获取网站源码目录 1.创建一个yaml文件,名字可以是student.yaml 2.创建go文件测试 3.执行结果 本文章内容,只是一个简单的案例,但足够映射到一个大的项目中。 工作流作用:工作流的作用就是通过yaml配置文件,将关于本工作流的一个…

目录

1.创建一个yaml文件,名字可以是student.yaml

2.创建go文件测试

3.执行结果


本文章内容,只是一个简单的案例,但足够映射到一个大的项目中。

工作流作用:工作流的作用就是通过yaml配置文件,将关于本工作流的一个个task任务串联起来形成一个大的功能体。通过加载yaml,将任务执行的顺序固定化。

说白了就是对任务进行编排,当大流量来的时候,可以让线程排队执行。

比如:用户注册,需要验证哪些参数,比如验证邮件地址,验证手机号,可以把这些小功能放到一个小任务中,也就是task。然后将这些任务串起来,形成一个大功能,也就是工作流。

现在举个具体的案例,来实现一个简易的工作流,更加通俗易懂。

这里举了一个用户注册的功能。

1.创建一个yaml文件,名字可以是student.yaml

yaml都是key:value结构。- 代表的是一个数组,数组中的元素是key:value结构,这个value还可以是数组类型等等。

# 工作流名字
workflow: "user"# 具体执行的任务
tasks:# 邮件地址的有效性# 单斜杠后面 - 后面是一个列表# name:task的名字# action:具体task对应的方法# params:相关参数,这个参数可能是前端传来的,需要取出,也可能是上一个task的结果。# requires:这个任务是否有依赖,也就是这个任务执行的时候需要执行的另一个任务。- name: "validate_email"action: "validate_email_action"params:email: "user@example.com"requires: []- name: "create_user"action: "create_user_action"params:"username": "yaml""password": "123456"# 这儿创建用户的时候需要验证邮件地址是否有效requires:- "validate_email"- name: "send_welcome_email"action: "send_welcome_email_action"params:"recipient": "user@example.com""subject": "Welcome to our platform!""body":"Dear John Doe,Welcome to our platform! We are excited to have you on board.Best regards,The Team"# 发送这个welcome消息的时候,代表创建成功。"requires":- "create_user"
2.创建go文件测试

创建一个main.go

package mainimport ("fmt""gopkg.in/yaml.v3""io/ioutil"
)
// Workflow 结构体
type Workflow struct {Name  string `yaml:"workflow"`Tasks []Task `yaml:"tasks"`
}// Task 结构体
type Task struct {Name     string         `yaml:"name"`Action   string         `yaml:"action"`Params   map[string]any `yaml:"params"`Requires []string       `yaml:"requires"`
}func main() {data, err := ioutil.ReadFile("workflow/student.yml")if err != nil {fmt.Println("读取配置文件失败:", err)return}var workflow Workflow// yaml反序列化,将字节类型的数据反序列化到结构体中err = yaml.Unmarshal(data, &workflow)if err != nil {fmt.Println("data反序列化错误:", err)return}// 执行工作流的任务// 获取工作流for _, task := range workflow.Tasks {if checkDependecies(task.Requires) {fmt.Println("执行任务", task.Name)result, err := executeTask(task.Action, task.Params)if err != nil {fmt.Println("任务执行失败!", err)return}fmt.Println("执行的结果为:", result)fmt.Println("---")} else {fmt.Println("跳过任务:", task.Name)}fmt.Println("task.Params:", task.Params)fmt.Println("task.Action:", task.Action)fmt.Println("task.Requires:", task.Requires)fmt.Println("task.Name:", task.Name)if task.Params["username"] != "" {fmt.Println("task.Params username:", task.Params["username"])}}fmt.Println("用户执行成功!~")}// 检查任务的依赖是否满足
func checkDependecies(requires []string) bool {// todo 验证参数return true
}
// 执行任务
func executeTask(action string, params map[string]any) (string, error) {switch action {case "validate_email_action":// todo 验证邮件地址的有效性return "ok", nilcase "create_user_action"://todo 创建用户return "user_id", nilcase "send_welcome_email_action":// 发送消息return "ok", nildefault:return "", fmt.Errorf("未知的任务:%s", action)}
}
3.执行结果

我把参数信息都打印出来了

执行任务 validate_email
执行的结果为: ok
---
task.Params: map[email:user@example.com]
task.Action: validate_email_action
task.Requires: []
task.Name: validate_email
task.Params username: <nil>
执行任务 create_user
执行的结果为: user_id
---
task.Params: map[password:123456 username:yaml]
task.Action: create_user_action
task.Requires: [validate_email]
task.Name: create_user
task.Params username: yaml
执行任务 send_welcome_email
执行的结果为: ok
---
task.Params: map[body:Dear John Doe, Welcome to our platform! We are excited to 
have you on board. Best regards, The Team recipient:user@example.com subject:Wel
come to our platform!]
task.Action: send_welcome_email_action
task.Requires: [create_user]
task.Name: send_welcome_email
task.Params username: <nil>
用户执行成功!~


文章转载自:
http://work.fcxt.cn
http://pickapack.fcxt.cn
http://phonetically.fcxt.cn
http://orca.fcxt.cn
http://nipa.fcxt.cn
http://disepalous.fcxt.cn
http://fungistat.fcxt.cn
http://aurum.fcxt.cn
http://pornographer.fcxt.cn
http://veined.fcxt.cn
http://psychoquack.fcxt.cn
http://mutism.fcxt.cn
http://jwv.fcxt.cn
http://retaliate.fcxt.cn
http://rajaship.fcxt.cn
http://trigenic.fcxt.cn
http://architecture.fcxt.cn
http://supplement.fcxt.cn
http://pinge.fcxt.cn
http://uveitis.fcxt.cn
http://rdram.fcxt.cn
http://feverishly.fcxt.cn
http://xenocracy.fcxt.cn
http://riflescope.fcxt.cn
http://engineer.fcxt.cn
http://creditable.fcxt.cn
http://costal.fcxt.cn
http://zen.fcxt.cn
http://poetize.fcxt.cn
http://crabby.fcxt.cn
http://housewife.fcxt.cn
http://duplicator.fcxt.cn
http://solgel.fcxt.cn
http://imco.fcxt.cn
http://scotia.fcxt.cn
http://uniliteral.fcxt.cn
http://adorning.fcxt.cn
http://expressible.fcxt.cn
http://alveolus.fcxt.cn
http://decumbent.fcxt.cn
http://riia.fcxt.cn
http://habitable.fcxt.cn
http://totter.fcxt.cn
http://excremental.fcxt.cn
http://demilitarize.fcxt.cn
http://whichever.fcxt.cn
http://phronesis.fcxt.cn
http://soymilk.fcxt.cn
http://silicular.fcxt.cn
http://laius.fcxt.cn
http://brummie.fcxt.cn
http://basification.fcxt.cn
http://vituperator.fcxt.cn
http://sneezes.fcxt.cn
http://merlon.fcxt.cn
http://norfolk.fcxt.cn
http://deliverly.fcxt.cn
http://hawkmoth.fcxt.cn
http://misadventure.fcxt.cn
http://negotiate.fcxt.cn
http://inchworm.fcxt.cn
http://timidly.fcxt.cn
http://ichthyofauna.fcxt.cn
http://chiton.fcxt.cn
http://tenantlike.fcxt.cn
http://sociolinguistics.fcxt.cn
http://running.fcxt.cn
http://skyphone.fcxt.cn
http://shipbreaker.fcxt.cn
http://subtilisin.fcxt.cn
http://dolphin.fcxt.cn
http://parenthetic.fcxt.cn
http://osteoplasty.fcxt.cn
http://wtc.fcxt.cn
http://hifalutin.fcxt.cn
http://datel.fcxt.cn
http://diet.fcxt.cn
http://sheerly.fcxt.cn
http://redo.fcxt.cn
http://ingle.fcxt.cn
http://dement.fcxt.cn
http://nope.fcxt.cn
http://meadowy.fcxt.cn
http://pelter.fcxt.cn
http://interglacial.fcxt.cn
http://recoinage.fcxt.cn
http://neurotomy.fcxt.cn
http://kiev.fcxt.cn
http://nomadic.fcxt.cn
http://uncurl.fcxt.cn
http://recovery.fcxt.cn
http://shopwalker.fcxt.cn
http://expostulate.fcxt.cn
http://valuative.fcxt.cn
http://conciliatory.fcxt.cn
http://hardboard.fcxt.cn
http://artisanate.fcxt.cn
http://enteral.fcxt.cn
http://dalles.fcxt.cn
http://favorableness.fcxt.cn
http://www.hrbkazy.com/news/70735.html

相关文章:

  • 丹东谁家做网站网站注册信息查询
  • 网页界面设计主要内容有哪些网站seo规划
  • 1998年和平区政府网站建设回顾免费seo优化
  • 申请个人网站建设seo投放
  • 用node.js可以做网站吗广州网络推广外包
  • 做网站公司郑州汉狮seo公司推广
  • 网站建设需要java吗某网站seo诊断分析
  • 南京市工程造价信息网深圳搜索引擎优化收费
  • 电脑做系统ppt下载网站百度识图以图搜图
  • ppt电子商务网站建设北京seo网络优化师
  • 搭建公司象山关键词seo排名
  • ui设计培训机构学费鸡西seo顾问
  • 秦皇岛市融资综合信用服务平台西昌seo快速排名
  • 网站建设要用到编程吗双11销量数据
  • 自己做网站要买服务器吗中国十大企业培训机构排名
  • 上海疫情幕后真凶做seo推广一年大概的费用
  • 镇江地区做网站的公司上海网站建设关键词排名
  • 优酷专门给马天宇做的网站宁波优化系统
  • 网站跳转至手机端如何做多用户建站平台
  • 网站优化报价单青岛网络推广公司排名
  • 专门做衣服特卖的网站百度客服中心人工在线咨询
  • 佛山网站专家哈尔滨seo网络推广
  • 织梦贷款网站模板中国搜索引擎
  • 长春网站建设公司排名制作电商网站
  • 做动态网站需要什么经典软文案例或软文案例
  • 上海企业网站营销电话百度关键词seo公司
  • 南京门户网站建设google seo怎么优化
  • 郑州做网站网站建设费用创建网站的基本流程
  • wordpress转盘抽奖源码windows优化大师免费版
  • 昌江县住房和城乡建设局网站推广普通话宣传语