Golang中的强制返回错误

I want to test how certain code handles errors.

I want a function to return an error.

I have tried typing return 0/0 but then my application won't build

How can I force return an error?

you can return errors like this:

func ReturnError() (string, error){       
      return "", fmt.Errorf("this is an %s error", "internal server")
      // or
      return "", errors.New("this is an error")
}

You can use the errors package.

import "errors"

// [ ... ]

func failFunc() error {
    return errors.New("Error message")
}

Here's the godoc: https://godoc.org/errors