本站源代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
863B

  1. package gcfg
  2. import (
  3. "gopkg.in/warnings.v0"
  4. )
  5. // FatalOnly filters the results of a Read*Into invocation and returns only
  6. // fatal errors. That is, errors (warnings) indicating data for unknown
  7. // sections / variables is ignored. Example invocation:
  8. //
  9. // err := gcfg.FatalOnly(gcfg.ReadFileInto(&cfg, configFile))
  10. // if err != nil {
  11. // ...
  12. //
  13. func FatalOnly(err error) error {
  14. return warnings.FatalOnly(err)
  15. }
  16. func isFatal(err error) bool {
  17. _, ok := err.(extraData)
  18. return !ok
  19. }
  20. type extraData struct {
  21. section string
  22. subsection *string
  23. variable *string
  24. }
  25. func (e extraData) Error() string {
  26. s := "can't store data at section \"" + e.section + "\""
  27. if e.subsection != nil {
  28. s += ", subsection \"" + *e.subsection + "\""
  29. }
  30. if e.variable != nil {
  31. s += ", variable \"" + *e.variable + "\""
  32. }
  33. return s
  34. }
  35. var _ error = extraData{}
上海开阖软件有限公司 沪ICP备12045867号-1