Slide 27
Slide 27 text
Error Propagation
When a function encounters an error in a go application, the
conventional approach is to return it up the call chain. Errors
may be returned unmodified or, as in our example below,
wrapped with context.
func NewFromJSON( s [ ] byte ) (∗User , error ) {
u := &User { }
i f err := json . Unmarshal ( s , u ) ; err != n i l {
return nil , errors . Wrap( err , " f a i l e d to d e s e r i a l i z e JSON data " )
}
return u , n i l
}
19