diff options
author | Alexander Kiryukhin <a.kiryukhin@mail.ru> | 2020-07-25 01:35:31 +0300 |
---|---|---|
committer | Alexander Kiryukhin <a.kiryukhin@mail.ru> | 2020-07-25 01:35:31 +0300 |
commit | 4b35f7c2c3edc5c2fc8a9198dca3cd4031ecc2ed (patch) | |
tree | c39fd7d8e1fd2ccd9a224c179d33e1225b318a51 /downloader.go |
Diffstat (limited to 'downloader.go')
-rw-r--r-- | downloader.go | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/downloader.go b/downloader.go new file mode 100644 index 0000000..bda3d92 --- /dev/null +++ b/downloader.go @@ -0,0 +1,42 @@ +/* +Copyright © 2020 Alexander Kiryukhin <a.kiryukhin@mail.ru> + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ +package main + +import ( + "encoding/xml" + "fmt" + "net/http" +) + +func download(url string) (*InXML, error) { + cl := http.DefaultClient + resp, err := cl.Get(url) + if err != nil { + return nil, err + } + defer resp.Body.Close() + if resp.StatusCode != 200 { + return nil, fmt.Errorf("expected code 200, got %d (%s)", resp.StatusCode, resp.Status) + } + d := new(InXML) + return d, xml.NewDecoder(resp.Body).Decode(d) +} |