kos/entry/http/handle.go

31 lines
742 B
Go
Raw Normal View History

2023-04-23 17:57:36 +08:00
package http
import (
"encoding/json"
"fmt"
"net/http"
)
type (
NotFound struct {
}
NotAllowed struct {
}
)
func (n NotFound) ServeHTTP(writer http.ResponseWriter, request *http.Request) {
writer.WriteHeader(http.StatusNotFound)
json.NewEncoder(writer).Encode(responsePayload{
Code: http.StatusNotFound,
Reason: fmt.Sprintf("requested URL %s was not found on this server", request.URL.Path),
})
}
func (n NotAllowed) ServeHTTP(writer http.ResponseWriter, request *http.Request) {
writer.WriteHeader(http.StatusMethodNotAllowed)
json.NewEncoder(writer).Encode(responsePayload{
Code: http.StatusMethodNotAllowed,
Reason: fmt.Sprintf("%s URL %s was not allow on this server", request.Method, request.URL.Path),
})
}