func handler(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "text/plain; charset=UTF-8")
	if auth(r) == false {
		w.Header().Set("WWW-Authenticate", `Basic realm="MY REALM"`)
		w.WriteHeader(401)
		w.Write([]byte("401 Unauthorized\n"))
		return
	}
	if strings.Contains(r.URL.Path, "favicon.ico") {
		w.WriteHeader(404)
		return
	}
	text, err := transEnc(cmd(com), encode)
	if err != nil {
		fmt.Fprintln(os.Stderr, err.Error())
	}
	arr := strings.Split(text, "\n")
	if head > 0 && len(arr) > head {
		fmt.Fprint(w, strings.Join(arr[:head], "\n"))
	} else if head < 0 && len(arr) > -1*head {
		fmt.Fprint(w, strings.Join(arr[len(arr)+head-1:], "\n"))
	} else {
		fmt.Fprint(w, text)
	}
}
handler: command result
package main
import (
	"bytes"
	"flag"
	"fmt"
	"net/http"
	"os"
	"os/exec"
	"runtime"
	"strconv"
	"strings"
	"time"
	"golang.org/x/net/html/charset"
	"golang.org/x/text/transform"
)
var (
	port   int
	head   int
	user   string
	pass   string
	com    string
	open   bool
	encode string
)
func main() {
	flag.IntVar(&port, "p", 8080, "Port /default:8080")
	flag.IntVar(&head, "h", 0, "Prints the first N lines.If minus value then prints the last N lines.")
	flag.BoolVar(&open, "o", false, "Open web browser")
	flag.StringVar(&user, "user", "", "User (BASIC AUTH)")
	flag.StringVar(&pass, "pass", "", "Pass (BASIC AUTH)")
	flag.StringVar(&encode, "e", "utf-8", "Input encoding")
	flag.Usage = func() {
		fmt.Printf("Convert the command to a web server \n\n")
		flag.PrintDefaults()
	}
	flag.Parse()
	if len(flag.Args()) == 0 {
		flag.Usage()
		return
	}
	com = strings.Join(flag.Args(), " ")
	url := "http://localhost" + ":" + strconv.Itoa(port)
	go func() {
		if open == true {
			time.Sleep(500 * time.Millisecond)
			switch runtime.GOOS {
			case "linux":
				exec.Command("xdg-open", url).Start()
			case "windows":
				exec.Command("rundll32", "url.dll,FileProtocolHandler", url).Start()
			case "darwin":
				exec.Command("open", url).Start()
			}
		}
	}()
	fmt.Println(url)
	fmt.Println("Stop: Ctrl+C")
	http.HandleFunc("/", handler)
	err := http.ListenAndServe(":"+strconv.Itoa(port), nil)
	if err != nil {
		fmt.Fprintln(os.Stderr, err.Error())
		os.Exit(1)
	}
}