title: Creating a custom error in golang for http responses
body: <p>i wanted to create custom errors for my authentication service that i am currently working on.
  Since i have to create a error for every http responses, and i am fairly new to golang i am facing difficulties.
  The below code is the replica of the javascript code code that i wanted to implement here in go.</p>
  <pre><code>export abstract class CustomError extends Error {
  abstract statusCode: number;
  
  constructor(message: string) {
      super(message);
  
      Object.setPrototypeOf(this, CustomError.prototype);
  }
  
  abstract serializeErrors(): { message: string; field?: string }[];
  }
  </code></pre>
  <p>To create extended classes based on the custom error like this</p>
  <pre><code>import { CustomError } from &quot;./custom-error&quot;;
  
  export class NotFoundError extends CustomError {
  statusCode = 404;
  
  constructor() {
      super(&quot;Route not found&quot;);
  
      Object.setPrototypeOf(this, NotFoundError.prototype);
  }
  
  serializeErrors() {
      return [{ message: &quot;Not Found&quot; }];
   }
  }
  </code></pre>
  <p>so that i can be thrown or logged from the main file i.e.
  const existingUser = await User.findOne({ email });</p>
  <pre><code>    if (existingUser) {
          throw new BadRequestError(&quot;Email is already in use&quot;);
      }
  </code></pre>
  <p>so in simple language i wanted to create an object/model of <strong>CustomErrors</strong> that can help to create more diverse Erros like <strong>BadRequestError()</strong></p>
  <p>so, i need help regarding creating this one. <strong>And this is my first question here</strong></p>