Creating an HTTP Server in Go

This code snippet sets up a basic HTTP server in Go, serving a "Hello, HTTP!" message.

Creating an HTTP Server in Go
Photo by Alex Kotliarskyi / Unsplash

This code snippet sets up a basic HTTP server in Go, serving a "Hello, HTTP!" message.

package main

import (
    "fmt"
    "net/http"
)

func handler(w http.ResponseWriter, r *http.Request) {
    fmt.Fprintf(w, "Hello, HTTP!")
}

func main() {
    http.HandleFunc("/", handler)
    fmt.Println("Server is running on :8080...")
    http.ListenAndServe(":8080", nil)
}