You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
565 B
Go
31 lines
565 B
Go
package shrty
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"time"
|
|
)
|
|
|
|
|
|
func CheckURL(d *Data) error {
|
|
// Set a timeout for the Request
|
|
var netClient = &http.Client{
|
|
Timeout: time.Second * 10,
|
|
}
|
|
|
|
resp, err := netClient.Get(d.URL)
|
|
if err != nil {
|
|
d.URLFetched = d.URL
|
|
d.HTTPStatusCode = http.StatusGatewayTimeout
|
|
return nil
|
|
}
|
|
defer resp.Body.Close()
|
|
|
|
// Set the Informations from the Request
|
|
d.HTTPStatusCode = resp.StatusCode
|
|
d.URLFetched = fmt.Sprint(resp.Request.URL)
|
|
d.OriginalURL = fmt.Sprint(resp.Request.URL)
|
|
d.Domain = resp.Request.URL.Host
|
|
|
|
return err
|
|
} |