Coder Social home page Coder Social logo

eg's Introduction

eg

Here is an application that generates error variables from a YAML configuration file.

eg [flags]

Options

  -f, --file string      a YAML configuration file (default "config-example.yaml")
  -h, --help             help for eg
  -o, --output string    Output file (default "./errors/errors.go")
  -p, --package string   the Go package name (default "errors")

Example

eg -p errors -f errors-example.yaml -o out/errors.go
eg -f errors-example.yaml -o out/errors.md -t md

example config file: config-example.yaml

ErrInvalidInput:
  code: 4000
  status: 400
  message: Invalid input provided

ErrInternal:
  code: 5000
  status: 500
  message: Internal server error

example output

// Code generated by go tool eg; DO NOT EDIT.

package errors

import (
	"errors"
)

type Error struct {
	Status  int
	Code    int    `json:"code"`
	Message string `json:"message"`
}

var (
	ErrInternal = &Error{
		Code:    5000,
		Status:  500,
		Message: "Internal server error",
	}
	ErrInvalidInput = &Error{
		Code:    4000,
		Status:  400,
		Message: "Invalid input provided",
	}
)

// Is a wrapper of built-in errors.Is
func Is(err, target error) bool {
	return errors.Is(err, target)
}

// As a wrapper of built-in errors.As
func As(err error, target any) bool {
	return errors.As(err, target)
}
| Status | Code |         Message        |
|--------|------|------------------------|
|   400  | 4000 | Invalid input provided |
|   500  | 5000 |  Internal server error |

eg's People

Contributors

dinhquockhanh avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.