mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2024-12-15 19:41:36 +03:00
25 lines
595 B
Go
25 lines
595 B
Go
|
// Package aghhttp provides some common methods to work with HTTP.
|
||
|
package aghhttp
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"io"
|
||
|
"net/http"
|
||
|
|
||
|
"github.com/AdguardTeam/golibs/log"
|
||
|
)
|
||
|
|
||
|
// OK responds with word OK.
|
||
|
func OK(w http.ResponseWriter) {
|
||
|
if _, err := io.WriteString(w, "OK\n"); err != nil {
|
||
|
log.Error("couldn't write body: %s", err)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// Error writes formatted message to w and also logs it.
|
||
|
func Error(r *http.Request, w http.ResponseWriter, code int, format string, args ...interface{}) {
|
||
|
text := fmt.Sprintf(format, args...)
|
||
|
log.Error("%s %s: %s", r.Method, r.URL, text)
|
||
|
http.Error(w, text, code)
|
||
|
}
|