errproxy

module
v0.0.0-...-d29151c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 11, 2024 License: MIT

README

errproxy

Render compile and runtime errors directly in browser.

Screenshot

Middleware

Install
go get github.com/tigrang/errpoxy
Usage
package main

import (
	"github.com/go-chi/chi/v5"
	"github.com/tigrang/errproxy/debug"
	"github.com/tigrang/errproxy/throw"
)

func main() {
	debug.DebugEnabled = true // 1. enable stacktrace rendering

	r := chi.NewRouter()
	r.Use(debug.RecoverRenderer("http://localhost:3001")) // 2. use middleware

	r.Get("/foo", func(w http.ResponseWriter, r *http.Request) {
		if err := doSomething(); err != nil {
			fmt.Println(err) // Note: will not reach here when debug is enabled
			return
		}

		w.Write("...")
	})
}

func doSomething() error {
	// 3. wrap errors in throw.Err() -- panics when debug.DebugEnabled is true
	return throw.Err(errors.New("error"))
}

Proxy

Start proxy server
go run github.com/tigrang/errproxy/cmd/errproxy@latest \
        --proxybind localhost:9000 \
        --proxy http://localhost:3001 \

This starts proxy listening on localhost:9000 and forwarding requests to http://localhost:3001.

Notify proxy to rebuild

Update cmd config for air to notify the proxy it needs to rebuild. errproxy will execute build command in --app directory, parsing the output for errors to render in browser.

[build]
  cmd = "errproxy --notify --timeout 10 --app $(pwd) --proxy http://localhost:3001"
  ...

Directories

Path Synopsis
cmd
errproxy command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL