package main

import (
	"fmt"
	"net/http"
	"os"
	"strings"
)

func main() {
	CheckArgsHttp(os.Args[1:]) //1.8
	for _, url := range os.Args[1:] {
		resp, err := http.Get(url)
		if err != nil {
			fmt.Fprintf(os.Stderr,
				"Fetch: %v", err)
			os.Exit(1)
		}
		// 获得http协议状态码
		fmt.Printf("%s status:%s code:%d \n", url, resp.Status, resp.StatusCode)
		//_, err = io.Copy(os.Stdout, resp.Body)
		//if err != nil{
		//	fmt.Fprintf(os.Stderr,
		//		"Fetch: %s as %v", url,err)
		//	os.Exit(1)
		//}
		//resp.Body.Close()
	}
}
func CheckArgsHttp(args []string) {
	for i, _ := range args {
		// 去除 空格
		args[i] = strings.TrimSpace(args[i])
		// 去除 /
		args[i] = strings.Trim(args[i], "/")
		// 添加 http前缀
		if strings.HasPrefix(args[i], "http") == false {
			args[i] = "http://" + args[i]
		}
		fmt.Println(args[i])
	}
}
