func loadConfigFile(cfgPath string) (*config, error) { f, err := os.Open(cfgPath) if os.IsNotExist(err) { return &config{}, nil } else if err != nil { return nil, errors.New("failed to open config file %q: %s", cfgPath, err) } defer f.Close() var c *config if err := json.NewDecoder(f).Decode(&c); err != nil { return nil, errors.New("failed to parse config file %q: %s", cfgPath, err) } return c, nil }
func recoverPanicsFunc(next web.HTTPHandle) web.HTTPHandle { return func(rw http.ResponseWriter, r *http.Request, c *ctx.Context) (err error) { defer func() { // TODO maybe we should skip the additional stack lines. if r := recover(); r != nil { err = errors.New("panic: %s", r) } }() return next(rw, r, c) } }