Golang HTTP Server

// Code by Divyanshu Shekhar - https://divyanshushekhar.com/golang-http-server/

// Golang HTTP Server
package main

import (
	"fmt"
	"log"
	"net/http"
)

const (
	// Host name of the HTTP Server
	Host = "localhost"
	// Port of the HTTP Server
	Port = "8080"
)

func home(w http.ResponseWriter, r *http.Request) {
	fmt.Fprintf(w, "This is a Simple HTTP Web Server!")
}

func main() {
	http.HandleFunc("/", home)
	err := http.ListenAndServe(Host+":"+Port, nil)
	if err != nil {
		log.Fatal("Error Starting the HTTP Server : ", err)
		return
	}

}

3.8
10

                                    package main

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

func greet(w http.ResponseWriter, r *http.Request) {
	fmt.Fprintf(w, "Hello World! %s", time.Now())
}

func main() {
	http.HandleFunc("/", greet)
	http.ListenAndServe(":8080", nil)
}

3.8 (10 Votes)
0
Are there any code examples left?
New code examples in category Go
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
go create http server go http requestr golang server http http server in go golang create new http server golang http server from scratch go lang http request http request go go http.server http.server golang golang http3 server golang http2 server http server program in golang rest server golang golang http servers go run http server golang run http server golang http.Serve get http golang servehttp in go golang serverhttps in go golang http golang response http server on go http web server golang http golang server golang serve http api serve http golang http.response golang make http request go golang rest server golang http code HTTP server golang example http.Get go http.Request go http.client golang golang http client http server go create simple http server golang http client golang write an http server in golang golang http server get client launch http server golang golang http.Server go http.request simple golang http server go http. http.Serve golang server http golang http server golang golang http server request golang net/http server create a http server in golang go http server example golang create server HandleFunc http any go example http server go get net/http how to install go net/http go simple http server http.HandlerFunc() golang making http servers in golang golang http config http clients golang invloked from reusable http request golang helper http request golang helper built in server in golang golang http client library http get request golang http go example golang https client post example req.Header.add golang golang https https golang example goland server example create webserver golang go http get request golang sample http server app how to close http requesst body golang sample http server app golang is http request body nil in get request go send http request install go package http client := &http.Client { } serve content golang http client for golang http get golang go install http package go install net/http send web request in go http server example golang golang simple http server req.close golang simple go web server golang http package go make a request golang web server package golang http go http server library http.NewServeMux custom http client golang http request golang new http client golang golang make http request with headers golang create http server go fst http http.HandlerFunc http client golang make request request golang golang http request POST making http request golang go http handler golang go http response go web server golang http request get post golang golang net.client get golang setup http server golang net.client post golang post go server go make get request golang listen to server golang get request go webserver http.responsewriter go http request detail *http.Request in golang *http.Request in golang cannot convert http.StatusOK (untyped int constant 200) to func() intcompiler http server in golang golang web server http go how to make a golang server easy net/http configuration golang how to make a golang server go lang net http parseForm how to link golang to a html server web server in go webserver in go building a server with go web service in golang small example create web server golang writing servers in go go http server http.NewServeMux() file server go response write to golang http server manage post golang http example http golang web server in golang golang request golang http server example Golang HTTP Server
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source