package neterr import ( "fmt" "os" ) func Fatal(v ...interface{}) { fmt.Fprintln(os.Stderr, "manhttpd exited due to an error it could not recover from.") fmt.Fprintf(os.Stderr, "Error: %s\n", fmt.Sprint(v...)) os.Exit(1) } var ( Err400 = HTCode(400, "Bad Request", "Your request cannot be understood by the server.", "Check that you are using a release version of manhttpd.", "Please check spelling and try again.", "Otherwise browser extensions or proxies may be hijacking your requests.", ) Err404 = HTCode(404, "Not Found", "The requested does match any known page names. Please check your spelling and try again.", `If you cannot find the page using your system's man command, then you may need to update your manDB or apt-get <package>-doc.`, "If you can open a page using the cli but not in manhttpd, your service is misconfigured. For best results set user and group to your login user:", `You can edit </etc/systemd/system/manhttpd.service> and set "User=<your-user>" and "Group=<your-group>".`, `Usually root user will work just fine, however root does not index user pages. If manuals are installed without superuser, they are saved to <$HOME/.local/share/man/>.`, `If you want user pages you have to run manhttpd as your login user. If you really want to run the service as root with user directories, at your own risk: adding users' homes into the global path </etc/manpath.config> is usually safe but may cause catastrophic failure on some systems.`, ) Err500 = HTCode(500, "Internal Server Error", "The server encountered an error and could not complete your request.", "Make sure you are using a release version of manhttpd.", ) ) func HTCode(code int, name string, desc ...string) NetErr { return HTErr{code, name, desc} } func (h HTErr) Is(err error) bool { if err == nil { return false } return true } type HTErr struct { Code int Name string Desc []string } type NetErr interface { Error() HTErr Is(error) bool } func (e HTErr) Error() HTErr { return e } func (e HTErr) Title() string { return fmt.Sprintf("%d %s", e.Code, e.Name) } func (e HTErr) Content() string { s := fmt.Sprintf("
%s