fmthandler

command module
v0.0.0-...-8e157b2 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: MIT Imports: 14 Imported by: 0

README

fmthandler

fmthandler is a tool that enhances Go HTTP server code by automatically adding logging to HTTP HandlerFunc handlers. It parses the Abstract Syntax Tree (AST) of your code to achieve this.

Features
  • Automatically adds logging statements to HTTP HandlerFunc handlers.
  • Works seamlessly with both single files and entire directories of Go code.

Installation

go install github.com/behnambm/fmthandler@latest
Code Before
package main

import (
	"log"
	"net/http"
)

func main() {
	http.HandleFunc("/ping", func(w http.ResponseWriter, r *http.Request) {
		w.WriteHeader(200)
		w.Write([]byte("pong"))
	})

	err := http.ListenAndServe(":9090", nil)
	if err != nil {
		log.Fatalln(err)
	}

}

Running the fmthanlder
 fmthandler --file main.go
Code After
package main

import (
	"fmt"
	"log"
	"net/http"
)

func main() {
	http.HandleFunc("/ping", func(w http.ResponseWriter, r *http.Request) {
		fmt.Println("Invoking HandlerFunc: '/ping'")
		w.WriteHeader(200)
		w.Write([]byte("pong"))
	})

	err := http.ListenAndServe(":9090", nil)
	if err != nil {
		log.Fatalln(err)
	}

}

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

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