Skip to content

Commit

Permalink
build for windows
Browse files Browse the repository at this point in the history
  • Loading branch information
rnemeth90 committed Feb 5, 2024
1 parent 82fbcee commit ff03700
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 23 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ jobs:
fi
go mod tidy
go build -o httping -ldflags "-X main.Version=${GITHUB_REF_NAME} -X main.BuiltBy=github-actions" main.go
mv httping builds/
env GOOS=windows GOARCH=amd64 go build -o httping-win -ldflags "-X main.Version=${GITHUB_REF_NAME} -X main.BuiltBy=github-actions" main.go
mv httping* builds/
ls -lisa builds
- name: go test
Expand Down Expand Up @@ -94,7 +95,7 @@ jobs:
with:
name: ${{ env.GITHUB_REF_NAME }}
tag: ${{ env.GITHUB_REF_NAME }}
artifacts: ./cmd/httping/builds/httping
artifacts: ./cmd/httping/builds/httping*
bodyFile: "body.log"
token: ${{ secrets.GITHUB_TOKEN }}
removeArtifacts: true
Expand Down
42 changes: 23 additions & 19 deletions cmd/httping/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,21 @@ import (
// It includes the target URL, HTTP/HTTPS usage preference, count of pings,
// headers to be retrieved, and sleep duration between pings.
type config struct {
url string
useHTTP bool
count int
headers string
sleep int64
url string
useHTTP bool
count int
headers string
sleep int64
useragent string
}

var (
url string
useHTTP bool
count int
headers string
sleep int64
url string
useHTTP bool
count int
headers string
sleep int64
useragent string
)

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

config := config{
url: url,
useHTTP: useHTTP,
count: count,
headers: headers,
sleep: sleep,
url: url,
useHTTP: useHTTP,
count: count,
headers: headers,
sleep: sleep,
useragent: useragent,
}

go func() {
Expand All @@ -107,9 +111,9 @@ func main() {
}

// run executes the httping process based on the provided configuration and context.
// It handles pinging the specified URL, collecting response data, and writing the
// output to the provided writer. The function respects context cancellation,
// allowing for graceful termination. It accumulates statistics throughout the
// It handles pinging the specified URL, collecting response data, and writing the
// output to the provided writer. The function respects context cancellation,
// allowing for graceful termination. It accumulates statistics throughout the
// execution and prints a summary at the end or upon early termination.
func run(ctx context.Context, config config, writer io.Writer) error {
var count int
Expand Down Expand Up @@ -138,7 +142,7 @@ func run(ctx context.Context, config config, writer io.Writer) error {
fmt.Println(stats.String())
return ctx.Err()
default:
response, err := httping.MakeRequest(config.useHTTP, config.url, config.headers)
response, err := httping.MakeRequest(config.useHTTP, config.useragent, config.url, config.headers)
if err != nil {
return err
}
Expand Down
6 changes: 4 additions & 2 deletions httping.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,11 @@ func ParseURL(url string, useHTTP bool) string {

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

tr := &http.Transport{}
if !useHTTP {
Expand Down

0 comments on commit ff03700

Please sign in to comment.