amuz.es/src/infra/goutils@v0.1.3/net/json/resp_message.go (about) 1 package json 2 3 import ( 4 "bytes" 5 "net/http" 6 ) 7 8 var ( 9 // 200 10 ResponseOK = ResponseMessage(http.StatusText(http.StatusOK)) 11 ResponsePartialContent = ResponseMessage(http.StatusText(http.StatusPartialContent)) 12 13 // 300 14 ResponseMovedPermanently = ResponseMessage(http.StatusText(http.StatusMovedPermanently)) 15 ResponseFound = ResponseMessage(http.StatusText(http.StatusFound)) 16 ResponseSeeOther = ResponseMessage(http.StatusText(http.StatusSeeOther)) 17 ResponseTemporaryRedirect = ResponseMessage(http.StatusText(http.StatusTemporaryRedirect)) 18 ResponsePermanentRedirect = ResponseMessage(http.StatusText(http.StatusPermanentRedirect)) 19 ResponseUnauthorized = ResponseMessage(http.StatusText(http.StatusUnauthorized)) 20 ResponsePaymentRequired = ResponseMessage(http.StatusText(http.StatusPaymentRequired)) 21 22 // 400 23 ResponseBadRequest = ResponseMessage(http.StatusText(http.StatusBadRequest)) 24 ResponseForbidden = ResponseMessage(http.StatusText(http.StatusForbidden)) 25 ResponseNotFound = ResponseMessage(http.StatusText(http.StatusNotFound)) 26 ResponseMethodNotAllowed = ResponseMessage(http.StatusText(http.StatusMethodNotAllowed)) 27 ResponseNotAcceptable = ResponseMessage(http.StatusText(http.StatusNotAcceptable)) 28 ResponseRequestTimeout = ResponseMessage(http.StatusText(http.StatusRequestTimeout)) 29 ResponseConflict = ResponseMessage(http.StatusText(http.StatusConflict)) 30 ResponseGone = ResponseMessage(http.StatusText(http.StatusGone)) 31 ResponsePreconditionFailed = ResponseMessage(http.StatusText(http.StatusPreconditionFailed)) 32 ResponseRequestEntityTooLarge = ResponseMessage(http.StatusText(http.StatusRequestEntityTooLarge)) 33 ResponseRequestURITooLong = ResponseMessage(http.StatusText(http.StatusRequestURITooLong)) 34 ResponseUnsupportedMediaType = ResponseMessage(http.StatusText(http.StatusUnsupportedMediaType)) 35 ResponseUpgradeRequired = ResponseMessage(http.StatusText(http.StatusUpgradeRequired)) 36 ResponsePreconditionRequired = ResponseMessage(http.StatusText(http.StatusPreconditionRequired)) 37 ResponseTooManyRequests = ResponseMessage(http.StatusText(http.StatusTooManyRequests)) 38 ResponseRequestHeaderFieldsTooLarge = ResponseMessage(http.StatusText(http.StatusRequestHeaderFieldsTooLarge)) 39 ResponseUnavailableForLegalReasons = ResponseMessage(http.StatusText(http.StatusUnavailableForLegalReasons)) 40 41 // 500 42 ResponseInternalServerError = ResponseMessage(http.StatusText(http.StatusInternalServerError)) 43 ResponseNotImplemented = ResponseMessage(http.StatusText(http.StatusNotImplemented)) 44 ResponseBadGateway = ResponseMessage(http.StatusText(http.StatusBadGateway)) 45 ResponseServiceUnavailable = ResponseMessage(http.StatusText(http.StatusServiceUnavailable)) 46 ResponseGatewayTimeout = ResponseMessage(http.StatusText(http.StatusGatewayTimeout)) 47 ResponseHTTPVersionNotSupported = ResponseMessage(http.StatusText(http.StatusHTTPVersionNotSupported)) 48 ResponseInsufficientStorage = ResponseMessage(http.StatusText(http.StatusInsufficientStorage)) 49 ) 50 51 type ResponseMessage string 52 53 const ( 54 responseMessagePayloadStart = `{"message":"` 55 responseMessagePayloadEnd = `"}` 56 ) 57 58 func (rm ResponseMessage) MarshalJSON() ([]byte, error) { 59 buf := bytes.Buffer{} 60 buf.WriteString(responseMessagePayloadStart) 61 buf.WriteString(string(rm)) 62 buf.WriteString(responseMessagePayloadEnd) 63 64 return buf.Bytes(), nil 65 }