<i id="vtl0s"></i>
    <address id="vtl0s"><kbd id="vtl0s"></kbd></address>
  • \n
    \n
    \n\n\n\n

    style.css:<\/strong>
    \n<\/p>\n\n

    body {\n    font-family: Arial, sans-serif;\n    margin: 0;\n    padding: 0;\n    line-height: 1.6;\n    color: #333;\n    background-color: #f9f9f9;\n}\n\nheader {\n    background: #4caf50;\n    color: #fff;\n    padding: 20px 0;\n    text-align: center;\n}\nheader .profile-picture {\n    width: 150px;\n    height: 150px;\n    border-radius: 50%;\n    margin-bottom: 15px;\n}\nheader h1 {\n    font-size: 2.5em;\n    margin: 0;\n}\nheader .subtitle {\n    font-size: 1.2em;\n    margin: 0;\n}\nmain {\n    padding: 20px;\n    max-width: 800px;\n    margin: 20px auto;\n    background: #fff;\n    border-radius: 8px;\n    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);\n}\nmain .about,\nmain .links {\n    margin-bottom: 20px;\n}\nmain .links ul {\n    list-style: none;\n    padding: 0;\n}\nmain .links li {\n    margin: 10px 0;\n}\nmain .links a {\n    color: #4caf50;\n    text-decoration: none;\n    font-weight: bold;\n}\nmain .links a:hover {\n    text-decoration: underline;\n}\nfooter {\n    text-align: center;\n    padding: 10px 0;\n    background: #333;\n    color: #fff;\n}\n<\/pre>\n\n\n\n

    Output:
    \n<\/p>\n\n

    go run http_server.go\n<\/pre>\n\n\n\n

    \"xciting<\/p>\n\n\n


    \n\n

    \n \n \n ? Conclusion\n<\/h2>\n\n

    In this blog, we’ve explored three practical Go projects that help you get hands-on experience with different aspects of software development. From monitoring disk usage to building a simple HTTP server to hosting a portfolio website, and finally, creating a RESTful API to manage DevOps tools, these projects provide a solid foundation for anyone looking to sharpen their Go programming skills.<\/p><\/pre>\n

      \n
    • The disk usage monitoring application<\/strong> introduced you to system calls and basic file handling in Go, giving you insight into how you can interact with a machine’s file system.<\/li>\n
    • The HTTP server project<\/strong> allowed you to learn how to serve static files and handle basic health-check endpoints, helping you get started with web development in Go.<\/li>\n
    • The RESTful API project<\/strong> demonstrated how to structure an API, manage data with concurrency control, and make your application interactive through POST and GET requests.<\/li>\n<\/ul>\n\n

      Each of these projects is a building block that can be expanded upon to suit real-world applications. Whether you are interested in monitoring systems, developing web applications, or building APIs, Go provides the simplicity and power needed for efficient development.<\/p>\n\n

      ? For more informative blog, Follow me on Hashnode, X(Twitter) and LinkedIn.<\/p>\n\n

      Till then, Happy Coding!!<\/p>\n\n

      Happy Learning! ?<\/p>\n\n\n \n\n \n "}

      国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

      Home Backend Development Golang xciting Go-lang Projects to Kickstart Your DevOps Journey

      xciting Go-lang Projects to Kickstart Your DevOps Journey

      Dec 12, 2024 pm 02:21 PM

      ? Introduction

      Welcome to the world of DevOps! ? Today, I’m back with another exciting blog to help you dive deeper into practical programming for DevOps tasks. In my previous blog, we explored 3 Python projects that laid the foundation for DevOps automation.

      Now, let’s switch gears and explore the power of Go-lang! This blog will guide you through building 3 Go-lang projects that are both practical and beginner-friendly:

      • A Monitor Disk Usage tool for tracking storage stats.
      • Hosting a resume website using an HTTP server.
      • A RESTful API program to manage DevOps tools.

      So, grab your favorite code editor, and let’s get started! ?


      ? Pre-Requisites

      Before we dive into building these projects, let’s make sure your environment is set up and ready to go. Here’s what you need:

      1. Go (Golang)
      You’ll need to have Go installed on your system. Follow these steps based on your operating system:

      Windows

      • Download the latest Go installer from the official website.
      • Run the installer and follow the on-screen instructions.
      • Verify the installation by opening Command Prompt or PowerShell and typing:
      go version
      

      Ubuntu

      • Open a terminal and run:
      sudo apt update  
      sudo apt install -y golang
      
      • Verify the installation:
      go version
      

      macOS

      • Use Homebrew to install Go. Run:
      brew install go
      
      • Verify the installation:
      go version
      

      2. Basic Understanding of Go

      While you don’t need to be an expert, having a fundamental understanding of Go concepts like variables, functions, and structs will help you follow along smoothly. If you’re new to Go, I recommend exploring the Go Tour for a quick introduction.

      With these prerequisites met, you’re all set to start building these awesome Go-lang projects! ?


      ? Monitor Disk Usage App

      Let’s kick off our journey with the first project — a disk usage monitoring tool. This program will help you analyze disk usage for any specified directory on your system.

      You can find the source code in my GitHub repository. Let’s start by creating a file named disk_usage.go and adding the following code:

      package main
      
      import (
          "fmt"
          "os"
          "syscall"
      )
      func getDiskUsage(path string) {
          var stat syscall.Statfs_t
          err := syscall.Statfs(path, &stat)
          if err != nil {
              fmt.Println("Error Fetching Disk Usage:", err)
              return
          }
          total := stat.Blocks * uint64(stat.Bsize)
          free := stat.Bfree * uint64(stat.Bsize)
          used := total - free
          percentUsed := float64(used) / float64(total) * 100
          fmt.Printf("Disk usage of %s:\n", path)
          fmt.Printf("Total: %d GB\n", total/1e9)
          fmt.Printf("Used: %d GB (%.2f%%)\n", used/1e9, percentUsed)
          fmt.Printf("Free: %d GB\n", free/1e9)
      }
      func main() {
          path := "/"
          if len(os.Args) > 1 {
              path = os.Args[1]
          }
          _, err := os.Stat(path)
          if os.IsNotExist(err) {
              fmt.Printf("Error: '%s' Path doesn't exist.\n", path)
              return
          } else if err != nil {
              fmt.Printf("Error occurred while accessing path %s: %v \n", path, err)
              return
          }
          getDiskUsage(path)
      }
      

      How the Program Works:

      • The program uses the syscall.Statfs function to fetch disk statistics, including the total, used, and free space.
      • It calculates the percentage of disk space used and formats the output in a user-friendly way.
      • Error handling is implemented to check if the provided path exists or if there’s an issue accessing it.

      Running the Program
      To run the program, use the following commands:

      • Check the disk usage of a specific directory:
      go version
      
      • If no path is specified, the program defaults to the root directory (/):
      sudo apt update  
      sudo apt install -y golang
      

      xciting Go-lang Projects to Kickstart Your DevOps Journey

      Since I have a single partition, I will get the same result if I provide different paths.

      This project demonstrates how Go can interact with your system’s underlying APIs, making it a great starting point for system monitoring tasks. ?


      ? HTTP Server Program: Hosting a Portfolio Website

      The second project involves creating an HTTP server in Go that hosts a portfolio website. This project demonstrates how you can build and serve static websites while incorporating a health check endpoint for monitoring.

      You can find the source code in my GitHub repository.

      Steps to Build the HTTP Server

      • Create a file named http_server.go and add the following code:
      go version
      

      How It Works

      • Static File Server: The http.FileServer function serves files from the ./static directory.
      • Health Check Endpoint: A /health route is defined to provide a simple health check metric.
      • Server Setup: The server listens on port 8090 by default, and any errors during startup are logged.

      Creating the Portfolio Website

      1. Structure: Inside the static folder, create:

        • index.html
        • style.css
        • A folder named images with a profile picture named profile.jpeg.
      2. Add the following content to your files:

      index.html:

      brew install go
      

      Running the Program

      • Start the HTTP server with the following command:
      go version
      
      • Your portfolio website will now be available at: localhost:8090

      Accessing the Health Check
      To check the health of the server, visit:

      package main
      
      import (
          "fmt"
          "os"
          "syscall"
      )
      func getDiskUsage(path string) {
          var stat syscall.Statfs_t
          err := syscall.Statfs(path, &stat)
          if err != nil {
              fmt.Println("Error Fetching Disk Usage:", err)
              return
          }
          total := stat.Blocks * uint64(stat.Bsize)
          free := stat.Bfree * uint64(stat.Bsize)
          used := total - free
          percentUsed := float64(used) / float64(total) * 100
          fmt.Printf("Disk usage of %s:\n", path)
          fmt.Printf("Total: %d GB\n", total/1e9)
          fmt.Printf("Used: %d GB (%.2f%%)\n", used/1e9, percentUsed)
          fmt.Printf("Free: %d GB\n", free/1e9)
      }
      func main() {
          path := "/"
          if len(os.Args) > 1 {
              path = os.Args[1]
          }
          _, err := os.Stat(path)
          if os.IsNotExist(err) {
              fmt.Printf("Error: '%s' Path doesn't exist.\n", path)
              return
          } else if err != nil {
              fmt.Printf("Error occurred while accessing path %s: %v \n", path, err)
              return
          }
          getDiskUsage(path)
      }
      

      xciting Go-lang Projects to Kickstart Your DevOps Journey

      This project showcases how to use Go-lang to create a functional web server for hosting static content, with additional monitoring through a health check endpoint. ?


      ? RESTful API Project: Managing DevOps Tools

      In the final project of this blog, we’ll create a RESTful API that allows you to manage a list of DevOps tools. This program demonstrates the use of Go’s net/http package to handle RESTful routes and manage data.

      The complete source code is available on my GitHub repository.

      Building the RESTful API
      Step 1: Main Program
      Create a file named main.go and add the following code:

      go version
      

      Step 2: Data Handling
      In the tools directory, create a file named data.go and add:

      sudo apt update  
      sudo apt install -y golang
      

      Step 3: Handlers
      In the tools directory, create another file named handler.go and add:

      go version
      

      Initializing the Module

      Before running the program, initialize the Go module:

      brew install go
      

      This ensures the project can use the project/tools package.

      Running the Program
      Start the server by running:

      go version
      

      Testing the API

      1. List All Tools To fetch the list of tools, use:
      package main
      
      import (
          "fmt"
          "os"
          "syscall"
      )
      func getDiskUsage(path string) {
          var stat syscall.Statfs_t
          err := syscall.Statfs(path, &stat)
          if err != nil {
              fmt.Println("Error Fetching Disk Usage:", err)
              return
          }
          total := stat.Blocks * uint64(stat.Bsize)
          free := stat.Bfree * uint64(stat.Bsize)
          used := total - free
          percentUsed := float64(used) / float64(total) * 100
          fmt.Printf("Disk usage of %s:\n", path)
          fmt.Printf("Total: %d GB\n", total/1e9)
          fmt.Printf("Used: %d GB (%.2f%%)\n", used/1e9, percentUsed)
          fmt.Printf("Free: %d GB\n", free/1e9)
      }
      func main() {
          path := "/"
          if len(os.Args) > 1 {
              path = os.Args[1]
          }
          _, err := os.Stat(path)
          if os.IsNotExist(err) {
              fmt.Printf("Error: '%s' Path doesn't exist.\n", path)
              return
          } else if err != nil {
              fmt.Printf("Error occurred while accessing path %s: %v \n", path, err)
              return
          }
          getDiskUsage(path)
      }
      

      xciting Go-lang Projects to Kickstart Your DevOps Journey

      Output:

      go run disk_usage.go /path/to/directory
      
      1. Add a New Tool To add a new tool, use:
      go run disk_usage.go
      

      xciting Go-lang Projects to Kickstart Your DevOps Journey

      Output:

      package main
      import (
          "fmt"
          "net/http"
      )
      func healthCheckHandler(w http.ResponseWriter, r *http.Request) {
          w.WriteHeader(http.StatusOK)
          w.Write([]byte("OK"))
      }
      func main() {
          fs := http.FileServer(http.Dir("./static"))
          http.Handle("/", fs)
          http.HandleFunc("/health", healthCheckHandler)
          port := "8090"
          fmt.Printf("Starting server on port %s....", port)
          err := http.ListenAndServe(":"+port, nil)
          if err != nil {
              fmt.Println("Error starting server:", err)
          }
      }
      
      1. Fetch Tool Details To fetch details of a specific tool, use:
      <!DOCTYPE html>
      <html lang="en">
      <head>
          <meta charset="UTF-8">
          <meta name="viewport" content="width=device-width, initial-scale=1.0">
          <title>Pravesh Sudha - Portfolio</title>
          <link rel="stylesheet" href="style.css">
      </head>
      <body>
          <header>
              <div>
      
      
      
      <p><strong>style.css:</strong><br>
      </p>
      
      <pre class="brush:php;toolbar:false">body {
          font-family: Arial, sans-serif;
          margin: 0;
          padding: 0;
          line-height: 1.6;
          color: #333;
          background-color: #f9f9f9;
      }
      
      header {
          background: #4caf50;
          color: #fff;
          padding: 20px 0;
          text-align: center;
      }
      header .profile-picture {
          width: 150px;
          height: 150px;
          border-radius: 50%;
          margin-bottom: 15px;
      }
      header h1 {
          font-size: 2.5em;
          margin: 0;
      }
      header .subtitle {
          font-size: 1.2em;
          margin: 0;
      }
      main {
          padding: 20px;
          max-width: 800px;
          margin: 20px auto;
          background: #fff;
          border-radius: 8px;
          box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
      }
      main .about,
      main .links {
          margin-bottom: 20px;
      }
      main .links ul {
          list-style: none;
          padding: 0;
      }
      main .links li {
          margin: 10px 0;
      }
      main .links a {
          color: #4caf50;
          text-decoration: none;
          font-weight: bold;
      }
      main .links a:hover {
          text-decoration: underline;
      }
      footer {
          text-align: center;
          padding: 10px 0;
          background: #333;
          color: #fff;
      }
      

      Output:

      go run http_server.go
      

      xciting Go-lang Projects to Kickstart Your DevOps Journey


      ? Conclusion

      In this blog, we’ve explored three practical Go projects that help you get hands-on experience with different aspects of software development. From monitoring disk usage to building a simple HTTP server to hosting a portfolio website, and finally, creating a RESTful API to manage DevOps tools, these projects provide a solid foundation for anyone looking to sharpen their Go programming skills.

    • The disk usage monitoring application introduced you to system calls and basic file handling in Go, giving you insight into how you can interact with a machine’s file system.
    • The HTTP server project allowed you to learn how to serve static files and handle basic health-check endpoints, helping you get started with web development in Go.
    • The RESTful API project demonstrated how to structure an API, manage data with concurrency control, and make your application interactive through POST and GET requests.

    Each of these projects is a building block that can be expanded upon to suit real-world applications. Whether you are interested in monitoring systems, developing web applications, or building APIs, Go provides the simplicity and power needed for efficient development.

    ? For more informative blog, Follow me on Hashnode, X(Twitter) and LinkedIn.

    Till then, Happy Coding!!

    Happy Learning! ?

    The above is the detailed content of xciting Go-lang Projects to Kickstart Your DevOps Journey. For more information, please follow other related articles on the PHP Chinese website!

    Statement of this Website
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

    Hot AI Tools

    Undress AI Tool

    Undress AI Tool

    Undress images for free

    Undresser.AI Undress

    Undresser.AI Undress

    AI-powered app for creating realistic nude photos

    AI Clothes Remover

    AI Clothes Remover

    Online AI tool for removing clothes from photos.

    Clothoff.io

    Clothoff.io

    AI clothes remover

    Video Face Swap

    Video Face Swap

    Swap faces in any video effortlessly with our completely free AI face swap tool!

    Hot Tools

    Notepad++7.3.1

    Notepad++7.3.1

    Easy-to-use and free code editor

    SublimeText3 Chinese version

    SublimeText3 Chinese version

    Chinese version, very easy to use

    Zend Studio 13.0.1

    Zend Studio 13.0.1

    Powerful PHP integrated development environment

    Dreamweaver CS6

    Dreamweaver CS6

    Visual web development tools

    SublimeText3 Mac version

    SublimeText3 Mac version

    God-level code editing software (SublimeText3)

    Strategies for Integrating Golang Services with Existing Python Infrastructure Strategies for Integrating Golang Services with Existing Python Infrastructure Jul 02, 2025 pm 04:39 PM

    TointegrateGolangserviceswithexistingPythoninfrastructure,useRESTAPIsorgRPCforinter-servicecommunication,allowingGoandPythonappstointeractseamlesslythroughstandardizedprotocols.1.UseRESTAPIs(viaframeworkslikeGininGoandFlaskinPython)orgRPC(withProtoco

    Understanding the Performance Differences Between Golang and Python for Web APIs Understanding the Performance Differences Between Golang and Python for Web APIs Jul 03, 2025 am 02:40 AM

    Golangofferssuperiorperformance,nativeconcurrencyviagoroutines,andefficientresourceusage,makingitidealforhigh-traffic,low-latencyAPIs;2.Python,whileslowerduetointerpretationandtheGIL,provideseasierdevelopment,arichecosystem,andisbettersuitedforI/O-bo

    Is golang frontend or backend Is golang frontend or backend Jul 08, 2025 am 01:44 AM

    Golang is mainly used for back-end development, but it can also play an indirect role in the front-end field. Its design goals focus on high-performance, concurrent processing and system-level programming, and are suitable for building back-end applications such as API servers, microservices, distributed systems, database operations and CLI tools. Although Golang is not the mainstream language for web front-end, it can be compiled into JavaScript through GopherJS, run on WebAssembly through TinyGo, or generate HTML pages with a template engine to participate in front-end development. However, modern front-end development still needs to rely on JavaScript/TypeScript and its ecosystem. Therefore, Golang is more suitable for the technology stack selection with high-performance backend as the core.

    How to install Go How to install Go Jul 09, 2025 am 02:37 AM

    The key to installing Go is to select the correct version, configure environment variables, and verify the installation. 1. Go to the official website to download the installation package of the corresponding system. Windows uses .msi files, macOS uses .pkg files, Linux uses .tar.gz files and unzip them to /usr/local directory; 2. Configure environment variables, edit ~/.bashrc or ~/.zshrc in Linux/macOS to add PATH and GOPATH, and Windows set PATH to Go in the system properties; 3. Use the government command to verify the installation, and run the test program hello.go to confirm that the compilation and execution are normal. PATH settings and loops throughout the process

    How to build a GraphQL API in golang How to build a GraphQL API in golang Jul 08, 2025 am 01:03 AM

    To build a GraphQLAPI in Go, it is recommended to use the gqlgen library to improve development efficiency. 1. First select the appropriate library, such as gqlgen, which supports automatic code generation based on schema; 2. Then define GraphQLschema, describe the API structure and query portal, such as defining Post types and query methods; 3. Then initialize the project and generate basic code to implement business logic in resolver; 4. Finally, connect GraphQLhandler to HTTPserver and test the API through the built-in Playground. Notes include field naming specifications, error handling, performance optimization and security settings to ensure project maintenance

    Choosing a Microservice Framework: KitEx/GoMicro vs Python Flask/FastAPI Approaches Choosing a Microservice Framework: KitEx/GoMicro vs Python Flask/FastAPI Approaches Jul 02, 2025 pm 03:33 PM

    The choice of microservice framework should be determined based on project requirements, team technology stack and performance expectations. 1. Given the high performance requirements, KitEx or GoMicro of Go is given priority, especially KitEx is suitable for complex service governance and large-scale systems; 2. FastAPI or Flask of Python is more flexible in rapid development and iteration scenarios, suitable for small teams and MVP projects; 3. The team's skill stack directly affects the selection cost, and if there is already Go accumulation, it will continue to be more efficient. The Python team's rash conversion to Go may affect efficiency; 4. The Go framework is more mature in the service governance ecosystem, suitable for medium and large systems that need to connect with advanced functions in the future; 5. A hybrid architecture can be adopted according to the module, without having to stick to a single language or framework.

    Resource Consumption (CPU/Memory) Benchmarks for Typical Golang vs Python Web Services Resource Consumption (CPU/Memory) Benchmarks for Typical Golang vs Python Web Services Jul 03, 2025 am 02:38 AM

    Golang usually consumes less CPU and memory than Python when building web services. 1. Golang's goroutine model is efficient in scheduling, has strong concurrent request processing capabilities, and has lower CPU usage; 2. Go is compiled into native code, does not rely on virtual machines during runtime, and has smaller memory usage; 3. Python has greater CPU and memory overhead in concurrent scenarios due to GIL and interpretation execution mechanism; 4. Although Python has high development efficiency and rich ecosystem, it consumes a high resource, which is suitable for scenarios with low concurrency requirements.

    Go sync.WaitGroup example Go sync.WaitGroup example Jul 09, 2025 am 01:48 AM

    sync.WaitGroup is used to wait for a group of goroutines to complete the task. Its core is to work together through three methods: Add, Done, and Wait. 1.Add(n) Set the number of goroutines to wait; 2.Done() is called at the end of each goroutine, and the count is reduced by one; 3.Wait() blocks the main coroutine until all tasks are completed. When using it, please note: Add should be called outside the goroutine, avoid duplicate Wait, and be sure to ensure that Don is called. It is recommended to use it with defer. It is common in concurrent crawling of web pages, batch data processing and other scenarios, and can effectively control the concurrency process.

    See all articles