Skip to content

Commit

Permalink
chore: clean up linting
Browse files Browse the repository at this point in the history
  • Loading branch information
robdefeo committed Mar 29, 2020
1 parent 5376910 commit bdee69a
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 5 deletions.
4 changes: 3 additions & 1 deletion cmd/mailchain/internal/http/handlers/addresses.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,14 @@ func GetAddresses(ks keystore.Store) func(w http.ResponseWriter, r *http.Request
errs.JSONWriter(w, http.StatusUnprocessableEntity, errors.WithStack(err))
return
}
addresses := []string{}

rawAddresses, err := ks.GetAddresses(protocol, network)
if err != nil {
errs.JSONWriter(w, http.StatusInternalServerError, errors.WithStack(err))
return
}

addresses := []string{}
for _, x := range rawAddresses {
addresses = append(addresses, encoding.EncodeHex(x))
}
Expand Down
2 changes: 2 additions & 0 deletions cmd/mailchain/internal/http/handlers/pubkey.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,12 @@ func GetPublicKey(finders map[string]mailbox.PubKeyFinder) func(w http.ResponseW
errs.JSONWriter(w, http.StatusNotAcceptable, errors.Errorf("network %q not supported", req.Network))
return
}

if err != nil {
errs.JSONWriter(w, http.StatusInternalServerError, errors.WithStack(err))
return
}

encodedKey, encodingType, err := pubkey.EncodeByProtocol(publicKey.Bytes(), req.Protocol)
if err != nil {
errs.JSONWriter(w, http.StatusInternalServerError, errors.WithStack(err))
Expand Down
3 changes: 3 additions & 0 deletions cmd/mailchain/internal/http/handlers/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,18 @@ func GetRead(store stores.State) func(w http.ResponseWriter, r *http.Request) {
errs.JSONWriter(w, http.StatusNotAcceptable, errors.WithMessage(err, "invalid `message_id`"))
return
}

read, err := store.GetReadStatus(messageID)
if stores.IsNotFoundError(err) {
w.WriteHeader(http.StatusNotFound)
return
}

if err != nil {
errs.JSONWriter(w, http.StatusInternalServerError, err)
return
}

if err := json.NewEncoder(w).Encode(getBody{Read: read}); err != nil {
errs.JSONWriter(w, http.StatusInternalServerError, err)
return
Expand Down
6 changes: 4 additions & 2 deletions cmd/mailchain/internal/http/handlers/resolve_address.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,24 @@ func GetResolveAddress(resolvers map[string]nameservice.ReverseLookup) func(w ht
// 404: NotFoundError
// 422: ValidationError
return func(w http.ResponseWriter, hr *http.Request) {
ctx := hr.Context()
protocol, network, address, err := parseGetResolveAddressRequest(hr)
if err != nil {
errs.JSONWriter(w, http.StatusUnprocessableEntity, errors.WithStack(err))
return
}

resolver, ok := resolvers[fmt.Sprintf("%s/%s", protocol, network)]
if !ok {
errs.JSONWriter(w, http.StatusUnprocessableEntity, errors.Errorf("nameserver not supported on \"%s/%s\"", protocol, network))
return
}

if resolver == nil {
errs.JSONWriter(w, http.StatusUnprocessableEntity, errors.Errorf("no nameserver configured for \"%s/%s\"", protocol, network))
return
}

name, err := resolver.ResolveAddress(ctx, protocol, network, address)
name, err := resolver.ResolveAddress(hr.Context(), protocol, network, address)
if mailbox.IsNetworkNotSupportedError(err) {
errs.JSONWriter(w, http.StatusNotAcceptable, errors.Errorf("%q not supported", protocol+"/"+network))
return
Expand All @@ -69,6 +70,7 @@ func GetResolveAddress(resolvers map[string]nameservice.ReverseLookup) func(w ht
_ = json.NewEncoder(w).Encode(GetResolveAddressResponseBody{Status: nameservice.ErrorToRFC1035Status(err)})
return
}

if err != nil {
errs.JSONWriter(w, http.StatusInternalServerError, errors.WithStack(err))
return
Expand Down
8 changes: 6 additions & 2 deletions cmd/mailchain/internal/http/handlers/resolve_name.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,35 +43,39 @@ func GetResolveName(resolvers map[string]nameservice.ForwardLookup) func(w http.
// 404: NotFoundError
// 422: ValidationError
return func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
protocol, network, domainName, err := parseGetResolveNameRequest(r)
if err != nil {
errs.JSONWriter(w, http.StatusUnprocessableEntity, errors.WithStack(err))
return
}

resolver, ok := resolvers[fmt.Sprintf("%s/%s", protocol, network)]
if !ok {
errs.JSONWriter(w, http.StatusUnprocessableEntity, errors.Errorf("nameserver not supported on \"%s/%s\"", protocol, network))
return
}

if resolver == nil {
errs.JSONWriter(w, http.StatusUnprocessableEntity, errors.Errorf("no nameserver configured for \"%s/%s\"", protocol, network))
return
}

resolvedAddress, err := resolver.ResolveName(ctx, protocol, network, domainName)
resolvedAddress, err := resolver.ResolveName(r.Context(), protocol, network, domainName)
if mailbox.IsNetworkNotSupportedError(err) {
errs.JSONWriter(w, http.StatusNotAcceptable, errors.Errorf("%q not supported", protocol+"/"+network))
return
}

if nameservice.ErrorToRFC1035Status(err) > 0 {
_ = json.NewEncoder(w).Encode(GetResolveNameResponseBody{Status: nameservice.ErrorToRFC1035Status(err)})
return
}

if err != nil {
errs.JSONWriter(w, http.StatusInternalServerError, errors.WithStack(err))
return
}

encAddress, _, err := address.EncodeByProtocol(resolvedAddress, protocol)
if err != nil {
errs.JSONWriter(w, http.StatusInternalServerError, errors.WithMessage(err, "failed to encode address"))
Expand Down

0 comments on commit bdee69a

Please sign in to comment.