项目作者: coc1961

项目描述 :
execute a set of steps as a process controlling the cycle and error handling
高级语言: Go
项目地址: git://github.com/coc1961/process.git
创建时间: 2019-04-18T18:21:54Z
项目社区:https://github.com/coc1961/process

开源协议:

下载


process

Purpose

This framework has the purpose of simplifying the execution of processes and the evaluation of errors

Description

this framework allows to define a process as a set of steps that are executed until one of them fails. If one step fails the rest of the steps are not invoked

Example

This Code (without using process)

  1. func main() {
  2. person := &Person{Name: "Name", Age: 20}
  3. var err error
  4. if person, err = validate(person); err != nil {
  5. fmt.Println(err)
  6. return
  7. }
  8. if person, err = create(person); err != nil {
  9. fmt.Println(err)
  10. return
  11. }
  12. if person, err = audit(person); err != nil {
  13. fmt.Println(err)
  14. return
  15. }
  16. //Ok!!
  17. fmt.Println(person)
  18. }

Can be replaced by this

  1. func main() {
  2. //Create Process
  3. proc := createProcess()
  4. //Init process
  5. person := &Person{Name: "Name", Age: 20}
  6. //Execute the process
  7. //RullAll execute Validate,Create and Audit
  8. if proc.Start(person).RunAll().Error() != nil {
  9. //errors?
  10. fmt.Println(proc.Error())
  11. } else {
  12. //Ok!!!
  13. person := proc.Result().(*Person)
  14. fmt.Println(person)
  15. }
  16. }