Created
          February 10, 2020 07:29 
        
      - 
      
- 
        Save pratikmallya/97e7c180dedd13d22305c84de64234e8 to your computer and use it in GitHub Desktop. 
    echo server that returns different http status codes
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | package main | |
| import ( | |
| "github.com/labstack/echo" | |
| "net/http" | |
| ) | |
| func main() { | |
| e := echo.New() | |
| e.Use(FailDifferently) | |
| e.Logger.Fatal(e.Start(":8080")) | |
| return | |
| } | |
| func FailDifferently(next echo.HandlerFunc) echo.HandlerFunc { | |
| return func(c echo.Context) error { | |
| if c.Path() == "/100" {return echo.NewHTTPError(http.StatusContinue)} | |
| if c.Path() == "/101" {return echo.NewHTTPError(http.StatusSwitchingProtocols)} | |
| if c.Path() == "/102" {return echo.NewHTTPError(http.StatusProcessing)} | |
| if c.Path() == "/103" {return echo.NewHTTPError(http.StatusEarlyHints)} | |
| if c.Path() == "/200" {return echo.NewHTTPError(http.StatusOK)} | |
| if c.Path() == "/201" {return echo.NewHTTPError(http.StatusCreated)} | |
| if c.Path() == "/202" {return echo.NewHTTPError(http.StatusAccepted)} | |
| if c.Path() == "/203" {return echo.NewHTTPError(http.StatusNonAuthoritativeInfo)} | |
| if c.Path() == "/204" {return echo.NewHTTPError(http.StatusNoContent)} | |
| if c.Path() == "/205" {return echo.NewHTTPError(http.StatusResetContent)} | |
| if c.Path() == "/206" {return echo.NewHTTPError(http.StatusPartialContent)} | |
| if c.Path() == "/207" {return echo.NewHTTPError(http.StatusMultiStatus)} | |
| if c.Path() == "/208" {return echo.NewHTTPError(http.StatusAlreadyReported)} | |
| if c.Path() == "/226" {return echo.NewHTTPError(http.StatusIMUsed)} | |
| if c.Path() == "/300" {return echo.NewHTTPError(http.StatusMultipleChoices)} | |
| if c.Path() == "/301" {return echo.NewHTTPError(http.StatusMovedPermanently)} | |
| if c.Path() == "/302" {return echo.NewHTTPError(http.StatusFound)} | |
| if c.Path() == "/303" {return echo.NewHTTPError(http.StatusSeeOther)} | |
| if c.Path() == "/304" {return echo.NewHTTPError(http.StatusNotModified)} | |
| if c.Path() == "/305" {return echo.NewHTTPError(http.StatusUseProxy)} | |
| if c.Path() == "/307" {return echo.NewHTTPError(http.StatusTemporaryRedirect)} | |
| if c.Path() == "/308" {return echo.NewHTTPError(http.StatusPermanentRedirect)} | |
| if c.Path() == "/400" {return echo.NewHTTPError(http.StatusBadRequest)} | |
| if c.Path() == "/401" {return echo.NewHTTPError(http.StatusUnauthorized)} | |
| if c.Path() == "/402" {return echo.NewHTTPError(http.StatusPaymentRequired)} | |
| if c.Path() == "/403" {return echo.NewHTTPError(http.StatusForbidden)} | |
| if c.Path() == "/404" {return echo.NewHTTPError(http.StatusNotFound)} | |
| if c.Path() == "/405" {return echo.NewHTTPError(http.StatusMethodNotAllowed)} | |
| if c.Path() == "/406" {return echo.NewHTTPError(http.StatusNotAcceptable)} | |
| if c.Path() == "/407" {return echo.NewHTTPError(http.StatusProxyAuthRequired)} | |
| if c.Path() == "/408" {return echo.NewHTTPError(http.StatusRequestTimeout)} | |
| if c.Path() == "/409" {return echo.NewHTTPError(http.StatusConflict)} | |
| if c.Path() == "/410" {return echo.NewHTTPError(http.StatusGone)} | |
| if c.Path() == "/411" {return echo.NewHTTPError(http.StatusLengthRequired)} | |
| if c.Path() == "/412" {return echo.NewHTTPError(http.StatusPreconditionFailed)} | |
| if c.Path() == "/413" {return echo.NewHTTPError(http.StatusRequestEntityTooLarge)} | |
| if c.Path() == "/414" {return echo.NewHTTPError(http.StatusRequestURITooLong)} | |
| if c.Path() == "/415" {return echo.NewHTTPError(http.StatusUnsupportedMediaType)} | |
| if c.Path() == "/416" {return echo.NewHTTPError(http.StatusRequestedRangeNotSatisfiable)} | |
| if c.Path() == "/417" {return echo.NewHTTPError(http.StatusExpectationFailed)} | |
| if c.Path() == "/418" {return echo.NewHTTPError(http.StatusTeapot)} | |
| if c.Path() == "/421" {return echo.NewHTTPError(http.StatusMisdirectedRequest)} | |
| if c.Path() == "/422" {return echo.NewHTTPError(http.StatusUnprocessableEntity)} | |
| if c.Path() == "/423" {return echo.NewHTTPError(http.StatusLocked)} | |
| if c.Path() == "/424" {return echo.NewHTTPError(http.StatusFailedDependency)} | |
| if c.Path() == "/425" {return echo.NewHTTPError(http.StatusTooEarly)} | |
| if c.Path() == "/426" {return echo.NewHTTPError(http.StatusUpgradeRequired)} | |
| if c.Path() == "/428" {return echo.NewHTTPError(http.StatusPreconditionRequired)} | |
| if c.Path() == "/429" {return echo.NewHTTPError(http.StatusTooManyRequests)} | |
| if c.Path() == "/431" {return echo.NewHTTPError(http.StatusRequestHeaderFieldsTooLarge)} | |
| if c.Path() == "/451" {return echo.NewHTTPError(http.StatusUnavailableForLegalReasons)} | |
| if c.Path() == "/500" {return echo.NewHTTPError(http.StatusInternalServerError)} | |
| if c.Path() == "/501" {return echo.NewHTTPError(http.StatusNotImplemented)} | |
| if c.Path() == "/502" {return echo.NewHTTPError(http.StatusBadGateway)} | |
| if c.Path() == "/503" {return echo.NewHTTPError(http.StatusServiceUnavailable)} | |
| if c.Path() == "/504" {return echo.NewHTTPError(http.StatusGatewayTimeout)} | |
| if c.Path() == "/505" {return echo.NewHTTPError(http.StatusHTTPVersionNotSupported)} | |
| if c.Path() == "/506" {return echo.NewHTTPError(http.StatusVariantAlsoNegotiates)} | |
| if c.Path() == "/507" {return echo.NewHTTPError(http.StatusInsufficientStorage)} | |
| if c.Path() == "/508" {return echo.NewHTTPError(http.StatusLoopDetected)} | |
| if c.Path() == "/510" {return echo.NewHTTPError(http.StatusNotExtended)} | |
| if c.Path() == "/511" {return echo.NewHTTPError(http.StatusNetworkAuthenticationRequired)} | |
| return next(c) | |
| } | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
Install
Run
Hit it