github.com/GuanceCloud/cliutils@v1.1.21/dialtesting/task.go (about) 1 // Unless explicitly stated otherwise all files in this repository are licensed 2 // under the MIT License. 3 // This product includes software developed at Guance Cloud (https://www.guance.com/). 4 // Copyright 2021-present Guance, Inc. 5 6 // Package dialtesting defined dialtesting tasks and task implements. 7 package dialtesting 8 9 import ( 10 "fmt" 11 "net/url" 12 "time" 13 ) 14 15 const ( 16 StatusStop = "stop" 17 18 ClassHTTP = "HTTP" 19 ClassTCP = "TCP" 20 ClassWebsocket = "WEBSOCKET" 21 ClassICMP = "ICMP" 22 ClassDNS = "DNS" 23 ClassHeadless = "BROWSER" 24 25 ClassOther = "OTHER" 26 ) 27 28 type Task interface { 29 ID() string 30 Status() string 31 Run() error 32 Init() error 33 InitDebug() error 34 CheckResult() ([]string, bool) 35 Class() string 36 GetResults() (map[string]string, map[string]interface{}) 37 PostURLStr() string 38 MetricName() string 39 Stop() error 40 RegionName() string 41 AccessKey() string 42 Check() error 43 UpdateTimeUs() int64 44 GetFrequency() string 45 GetOwnerExternalID() string 46 SetOwnerExternalID(string) 47 GetLineData() string 48 GetHostName() (string, error) 49 GetWorkspaceLanguage() string 50 GetTagsInfo() string 51 52 SetRegionID(string) 53 SetAk(string) 54 SetStatus(string) 55 SetUpdateTime(int64) 56 57 Ticker() *time.Ticker 58 } 59 60 func getHostName(host string) (string, error) { 61 reqURL, err := url.Parse(host) 62 if err != nil { 63 return "", fmt.Errorf("parse host error: %w", err) 64 } 65 66 return reqURL.Hostname(), nil 67 }