Skip to content

Commit ff03700

Browse files
committed
build for windows
1 parent 82fbcee commit ff03700

File tree

3 files changed

+30
-23
lines changed

3 files changed

+30
-23
lines changed

.github/workflows/build.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ jobs:
4848
fi
4949
go mod tidy
5050
go build -o httping -ldflags "-X main.Version=${GITHUB_REF_NAME} -X main.BuiltBy=github-actions" main.go
51-
mv httping builds/
51+
env GOOS=windows GOARCH=amd64 go build -o httping-win -ldflags "-X main.Version=${GITHUB_REF_NAME} -X main.BuiltBy=github-actions" main.go
52+
mv httping* builds/
5253
ls -lisa builds
5354
5455
- name: go test
@@ -94,7 +95,7 @@ jobs:
9495
with:
9596
name: ${{ env.GITHUB_REF_NAME }}
9697
tag: ${{ env.GITHUB_REF_NAME }}
97-
artifacts: ./cmd/httping/builds/httping
98+
artifacts: ./cmd/httping/builds/httping*
9899
bodyFile: "body.log"
99100
token: ${{ secrets.GITHUB_TOKEN }}
100101
removeArtifacts: true

cmd/httping/main.go

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,21 @@ import (
1818
// It includes the target URL, HTTP/HTTPS usage preference, count of pings,
1919
// headers to be retrieved, and sleep duration between pings.
2020
type config struct {
21-
url string
22-
useHTTP bool
23-
count int
24-
headers string
25-
sleep int64
21+
url string
22+
useHTTP bool
23+
count int
24+
headers string
25+
sleep int64
26+
useragent string
2627
}
2728

2829
var (
29-
url string
30-
useHTTP bool
31-
count int
32-
headers string
33-
sleep int64
30+
url string
31+
useHTTP bool
32+
count int
33+
headers string
34+
sleep int64
35+
useragent string
3436
)
3537

3638
// init is an initialization function that sets up command-line flags
@@ -41,6 +43,7 @@ func init() {
4143
pflag.StringVar(&url, "url", "", "Specify the URL to ping. (required)")
4244
pflag.BoolVar(&useHTTP, "insecure", false, "Use HTTP instead of HTTPS. By default, HTTPS is used.")
4345
pflag.StringVar(&headers, "headers", "", "A comma-separated list of response headers to include in the output.")
46+
pflag.StringVar(&useragent, "user-agent", "", "The user-agent value to include in the request headers.")
4447
pflag.IntVar(&count, "count", 4, "Set the number of pings to send. Default is 4.")
4548
pflag.Int64Var(&sleep, "sleep", 0, "Set the delay (in seconds) between successive pings. Default is 0 (no delay).")
4649
pflag.Usage = usage
@@ -83,11 +86,12 @@ func main() {
8386
}
8487

8588
config := config{
86-
url: url,
87-
useHTTP: useHTTP,
88-
count: count,
89-
headers: headers,
90-
sleep: sleep,
89+
url: url,
90+
useHTTP: useHTTP,
91+
count: count,
92+
headers: headers,
93+
sleep: sleep,
94+
useragent: useragent,
9195
}
9296

9397
go func() {
@@ -107,9 +111,9 @@ func main() {
107111
}
108112

109113
// run executes the httping process based on the provided configuration and context.
110-
// It handles pinging the specified URL, collecting response data, and writing the
111-
// output to the provided writer. The function respects context cancellation,
112-
// allowing for graceful termination. It accumulates statistics throughout the
114+
// It handles pinging the specified URL, collecting response data, and writing the
115+
// output to the provided writer. The function respects context cancellation,
116+
// allowing for graceful termination. It accumulates statistics throughout the
113117
// execution and prints a summary at the end or upon early termination.
114118
func run(ctx context.Context, config config, writer io.Writer) error {
115119
var count int
@@ -138,7 +142,7 @@ func run(ctx context.Context, config config, writer io.Writer) error {
138142
fmt.Println(stats.String())
139143
return ctx.Err()
140144
default:
141-
response, err := httping.MakeRequest(config.useHTTP, config.url, config.headers)
145+
response, err := httping.MakeRequest(config.useHTTP, config.useragent, config.url, config.headers)
142146
if err != nil {
143147
return err
144148
}

httping.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,11 @@ func ParseURL(url string, useHTTP bool) string {
5959

6060
// MakeRequest performs an HTTP GET request to the specified URL.
6161
// It returns an HttpResponse struct filled with response data.
62-
func MakeRequest(useHTTP bool, url, headers string) (*HttpResponse, error) {
62+
func MakeRequest(useHTTP bool, userAgent, url, headers string) (*HttpResponse, error) {
6363
var result *HttpResponse
64-
userAgent := "httping"
64+
if userAgent == "" {
65+
userAgent = "httping"
66+
}
6567

6668
tr := &http.Transport{}
6769
if !useHTTP {

0 commit comments

Comments
 (0)