Documentation
¶
Index ¶
Constants ¶
const ( // ProcessEndpoint is the endpoint for creating a new voting process ProcessEndpoint = "/process" // PingEndpoint is the endpoint for checking the API status PingEndpoint = "/ping" // NewCensusEndpoint is the endpoint for creating a new census NewCensusEndpoint = "/census" // AddCensusParticipantsEndpoint is the endpoint for adding participants to a census AddCensusParticipantsEndpoint = "/census/participants" // GetCensusParticipantsEndpoint is the endpoint for getting the participants of a census GetCensusParticipantsEndpoint = "/census/participants" // GetCensusRootEndpoint is the endpoint for getting the root of a census GetCensusRootEndpoint = "/census/root" // GetCensusSizeEndpoint is the endpoint for getting the size of a census GetCensusSizeEndpoint = "/census/size" // DeleteCensusEndpoint is the endpoint for deleting a census DeleteCensusEndpoint = "/census" // GetCensusProofEndpoint is the endpoint for getting a proof of a census GetCensusProofEndpoint = "/census/proof" )
Variables ¶
var ( ErrResourceNotFound = Error{Code: 40001, HTTPstatus: http.StatusNotFound, Err: fmt.Errorf("resource not found")} ErrMalformedBody = Error{Code: 40004, HTTPstatus: http.StatusBadRequest, Err: fmt.Errorf("malformed JSON body")} ErrInvalidSignature = Error{Code: 40005, HTTPstatus: http.StatusBadRequest, Err: fmt.Errorf("invalid signature")} ErrMalformedProcessID = Error{Code: 40006, HTTPstatus: http.StatusBadRequest, Err: fmt.Errorf("malformed process ID")} ErrProcessNotFound = Error{Code: 40007, HTTPstatus: http.StatusNotFound, Err: fmt.Errorf("process not found")} ErrMarshalingServerJSONFailed = Error{Code: 50001, HTTPstatus: http.StatusInternalServerError, Err: fmt.Errorf("marshaling (server-side) JSON failed")} ErrGenericInternalServerError = Error{Code: 50002, HTTPstatus: http.StatusInternalServerError, Err: fmt.Errorf("internal server error")} ErrInvalidCensusID = Error{Code: 40020, HTTPstatus: http.StatusBadRequest, Err: fmt.Errorf("invalid census ID")} ErrCensusNotFound = Error{Code: 40021, HTTPstatus: http.StatusNotFound, Err: fmt.Errorf("census not found")} )
The custom Error type satisfies the error interface. Error() returns a human-readable description of the error.
Error codes in the 40001-49999 range are the user's fault, and they return HTTP Status 400 or 404 (or even 204), whatever is most appropriate.
Error codes 50001-59999 are the server's fault and they return HTTP Status 500 or 503, or something else if appropriate.
The initial list of errors were more or less grouped by topic, but the list grows with time in a random fashion. NEVER change any of the current error codes, only append new errors after the current last 4XXX or 5XXX If you notice there's a gap (say, error code 4010, 4011 and 4013 exist, 4012 is missing) DON'T fill in the gap, that code was used in the past for some error (not anymore) and shouldn't be reused. There's no correlation between Code and HTTP Status, for example the fact that Code 4045 returns HTTP Status 404 Not Found is just a coincidence
Do note that HTTPstatus 204 No Content implies the response body will be empty, so the Code and Message will actually be discarded, never sent to the client
Functions ¶
This section is empty.
Types ¶
type API ¶
type API struct {
// contains filtered or unexported fields
}
API type represents the API HTTP server with JWT authentication capabilities.
type APIConfig ¶
type APIConfig struct { Host string Port int Storage *stg.Storage // Optional: use existing storage instance }
APIConfig type represents the configuration for the API HTTP server. It includes the host, port and optionally an existing storage instance.
type CensusParticipant ¶
type CensusParticipant struct { Key types.HexBytes `json:"key"` Weight *types.BigInt `json:"weight,omitempty"` }
CensusParticipant is a participant in a census.
type CensusParticipants ¶
type CensusParticipants struct {
Participants []*CensusParticipant `json:"participants"`
}
CensusParticipants is a list of participants in a census.
type CensusRoot ¶
CensusRoot is the response to a census root request.
type Error ¶
Error is used by handler functions to wrap errors, assigning a unique error code and also specifying which HTTP Status should be used.
func (Error) MarshalJSON ¶
MarshalJSON returns a JSON containing Err.Error() and Code. Field HTTPstatus is ignored.
Example output: {"error":"account not found","code":4003}
func (Error) WithErr ¶
WithErr returns a copy of APIerror with err.Error() appended at the end of e.Err
func (Error) Withf ¶
Withf returns a copy of APIerror with the Sprintf formatted string appended at the end of e.Err
func (Error) Write ¶
func (e Error) Write(w http.ResponseWriter)
Write serializes a JSON msg using APIerror.Message and APIerror.Code and passes that to ctx.Send()