taharah / eop

Here you can find 2 approaches how to deal with errors: first one - return error, another one - panic. Which better - it's up to you!

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error or Panic

CircleCI Go Report Card Codacy Badge Maintainability

Here you can find 2 approaches how to deal with errors: first one - return error, another one - panic.
Which better - it's up to you!

Prerequisites

Common stuff between all approaches - workflow: here you can find one controller which calls service function which works like a facade and performs sign up into:

  • facebook
  • twitter
  • pinterest

you can see it on sequence diagram:

sequence diagram

Main idea

You can go through src/app/examples directory and find implementations for different approaches, you can compare different approaches and decide which one is better for you.
But regarding amount of code it looks like this: e VS p

Usage

To check that all approaches work in same way you can run:

git clone https://github.com/cn007b/eop.git && cd eop
export GOPATH=$PWD

# return error:
go run -race src/app/main.go --strategy=error
go run -race src/app/main.go --strategy=error --username=bond
go run -race src/app/main.go --strategy=error --username=james

# return error from goroutine:
go run -race src/app/main.go --strategy=error_goroutine
go run -race src/app/main.go --strategy=error_goroutine --username=bond
go run -race src/app/main.go --strategy=error_goroutine --username=james

# panic:
go run -race src/app/main.go --strategy=panic
go run -race src/app/main.go --strategy=panic --username=bond
go run -race src/app/main.go --strategy=panic --username=james

# panic in goroutine:
go run -race src/app/main.go --strategy=panic_goroutine
go run -race src/app/main.go --strategy=panic_goroutine --username=bond
go run -race src/app/main.go --strategy=panic_goroutine --username=james

# panic like PRO:
go run -race src/app/main.go --strategy=pro_panic
go run -race src/app/main.go --strategy=pro_panic --username=bond
go run -race src/app/main.go --strategy=pro_panic --username=james

# panic in goroutine like PRO:
go run -race src/app/main.go --strategy=pro_panic_goroutine
go run -race src/app/main.go --strategy=pro_panic_goroutine --username=bond
go run -race src/app/main.go --strategy=pro_panic_goroutine --username=james

About

Here you can find 2 approaches how to deal with errors: first one - return error, another one - panic. Which better - it's up to you!


Languages

Language:Go 100.0%