help@rskworld.in +91 93305 39277
RSK World
  • Home
  • Development
    • Web Development
    • Mobile Apps
    • Software
    • Games
    • Project
  • Technologies
    • Data Science
    • AI Development
    • Cloud Development
    • Blockchain
    • Cyber Security
    • Dev Tools
    • Testing Tools
  • About
  • Contact

Theme Settings

Color Scheme
Display Options
Font Size
100%
Back to Project
RSK World
go-cli-tool
/
internal
/
web
RSK World
go-cli-tool
Go CLI Tool v3.0 - Command-Line Interface with File Operations + Text Processing + System Monitoring + Cryptographic Tools + Network Utilities + HTTP Client + Image Processing + Cross-Platform Support + Modern Go Development
web
  • client.go1.7 KB
client.go
internal/web/client.go
Raw Download
Find: Go to:
/*
 * Project: Go CLI Tool
 * Category: Go Projects
 * Description: Command-line interface tool built with Go. Features file operations, text processing, command parsing, and system utilities.
 * Author: RSK World
 * Email: support@rskworld.in
 * Website: https://rskworld.in/contact.php
 * Year: 2026
 * Copyright (c) 2026 RSK World. All rights reserved.
 */

package web

import (
	"fmt"
	"io"
	"net/http"
	"time"

	"go-cli-tool/internal/ui"
)

// FetchURL fetches the content of the given URL and prints it.
func FetchURL(url string) {
	ui.Info(fmt.Sprintf("Fetching URL: %s", url))

	client := &http.Client{Timeout: 10 * time.Second}
	resp, err := client.Get(url)
	if err != nil {
		ui.Error(fmt.Sprintf("Failed to fetch URL: %v", err))
		return
	}
	defer resp.Body.Close()

	body, err := io.ReadAll(resp.Body)
	if err != nil {
		ui.Error(fmt.Sprintf("Failed to read response body: %v", err))
		return
	}

	ui.Success(fmt.Sprintf("Status: %s", resp.Status))
	fmt.Printf("Body length: %d bytes\n", len(body))
	fmt.Println("Body preview (first 200 chars):")
	if len(body) > 200 {
		fmt.Println(string(body[:200]) + "...")
	} else {
		fmt.Println(string(body))
	}
}

// GetHeaders fetches and prints the HTTP headers of the given URL.
func GetHeaders(url string) {
	ui.Info(fmt.Sprintf("Fetching headers for: %s", url))

	client := &http.Client{Timeout: 10 * time.Second}
	resp, err := client.Head(url)
	if err != nil {
		ui.Error(fmt.Sprintf("Failed to fetch headers: %v", err))
		return
	}
	defer resp.Body.Close()

	ui.Success(fmt.Sprintf("Status: %s", resp.Status))
	ui.Header("HEADERS")
	for k, v := range resp.Header {
		fmt.Printf("%s: %s\n", k, v)
	}
}
69 lines•1.7 KB
go

About RSK World

Founded by Molla Samser, with Designer & Tester Rima Khatun, RSK World is your one-stop destination for free programming resources, source code, and development tools.

Founder: Molla Samser
Designer & Tester: Rima Khatun

Development

  • Game Development
  • Web Development
  • Mobile Development
  • AI Development
  • Development Tools

Legal

  • Terms & Conditions
  • Privacy Policy
  • Disclaimer

Contact Info

Nutanhat, Mongolkote
Purba Burdwan, West Bengal
India, 713147

+91 93305 39277

hello@rskworld.in
support@rskworld.in

© 2026 RSK World. All rights reserved.

Content used for educational purposes only. View Disclaimer