forked from weikaishio/ali_mns
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix client proxy and improve client Send func interface
- Loading branch information
1 parent
6bdf5d6
commit 8ff1b55
Showing
5 changed files
with
89 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package ali_mns | ||
|
||
import ( | ||
"encoding/xml" | ||
"io" | ||
) | ||
|
||
type MNSDecoder interface { | ||
Decode(reader io.Reader, v interface{}) (err error) | ||
} | ||
|
||
type AliMNSDecoder struct { | ||
} | ||
|
||
func (p *AliMNSDecoder) Decode(reader io.Reader, v interface{}) (err error) { | ||
decoder := xml.NewDecoder(reader) | ||
err = decoder.Decode(&v) | ||
|
||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package ali_mns | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/gogap/errors" | ||
) | ||
|
||
func send(client MNSClient, decoder MNSDecoder, method Method, headers map[string]string, message interface{}, resource string, v interface{}) (statusCode int, err error) { | ||
var resp *http.Response | ||
if resp, err = client.Send(method, headers, message, resource); err != nil { | ||
return | ||
} | ||
|
||
if resp != nil { | ||
defer resp.Body.Close() | ||
statusCode = resp.StatusCode | ||
|
||
if resp.StatusCode != http.StatusCreated && | ||
resp.StatusCode != http.StatusOK && | ||
resp.StatusCode != http.StatusNoContent { | ||
|
||
errResp := ErrorMessageResponse{} | ||
if e := decoder.Decode(resp.Body, &errResp); e != nil { | ||
err = ERR_UNMARSHAL_ERROR_RESPONSE_FAILED.New(errors.Params{"err": e}) | ||
return | ||
} | ||
err = to_error(errResp, resource) | ||
return | ||
} | ||
|
||
if v != nil { | ||
if e := decoder.Decode(resp.Body, v); e != nil { | ||
err = ERR_UNMARSHAL_RESPONSE_FAILED.New(errors.Params{"err": e}) | ||
return | ||
} | ||
} | ||
} | ||
|
||
return | ||
} |