I have a variable like that in my Go stuff and trying to do it as same as in Java;
var (
STATUS = map[int]string{
200: "OK",
201: "Created",
202: "Accepted",
304: "Not Modified",
400: "Bad Request",
401: "Unauthorized",
403: "Forbidden",
404: "Not Found",
405: "Resource Not Allowed",
406: "Not Acceptable",
409: "Conflict",
412: "Precondition Failed",
415: "Bad Content Type",
416: "Requested Range Not Satisfiable",
417: "Expectation Failed",
500: "Internal Server Error",
}
)
I tried to use HashMap
or other array stuff but couldn't cos it would be a property of Response
class and must be defined at the beginning like;
package http;
class Response {
// here define filling it e.g STATUS = new Array(200, "OK", ...) etc..
... STATUS ...
}
Yes, I can fill it in constructor using HashMap
but then I can't get e.g "OK" like this: String status = STATUS[200]
.