network

package
v0.0.0-...-c438571 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 22, 2019 License: BSD-2-Clause Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MustGet

func MustGet(url string) ([]byte, error)

//0故障 -1无效文件 1成功

func LoadRemoteFile(url string) ([]byte,int) {
	resp, err := http.DefaultClient.Get(url)
	if err != nil {
		fmt.Println(err)
		return nil,0
	}
	defer resp.Body.Close()

	if resp.StatusCode == http.StatusNotFound || resp.StatusCode == http.StatusForbidden {
		return  nil,-1
	}

	if resp.StatusCode != http.StatusOK {
		fmt.Println(err, resp.StatusCode, url)
		return  nil,0
	}

	clen := resp.Header.Get("Content-Length")

	data,err := ioutil.ReadAll(resp.Body)
	if err != nil {
		fmt.Println(err)
		return  nil,0
	}

	if clen != "" {
		tlen, _ := strconv.Atoi(clen)
		if len(data) != tlen {
			fmt.Println(len(data), tlen)
			return  nil,0
		}
	}
	return data,1
}

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL