Example of a HTTP server in Go to handle GET requests from memory
Nov 03 '21

This an example of a simple HTTP server written in Go. It handles GET requests, matches the URL path to a function, and returns a HTML response from a global variable.

We are using the small FastHTTP library that adds a worker pool of goroutines for faster response time.

package main

import (

var x1 = `<!DOCTYPE html>
<html lang="en">
<title>This is a Website</title>
Xor The World!

func main() {

h0 := func(ctx *fasthttp.RequestCtx) {

switch string(ctx.Path()) {

        case "/":
           ctx.SetContentType("text/html; charset=utf8")



s := &fasthttp.Server{
       Name: "XOR Server",
       Handler: h0,

You can compile the program for any OS, and run it on the background. In Linux for example you will run it as  nohup ./server > /dev/null 2>&1 &  where standard output from the server log gets redirected to dev/null.

© 2021 Thexor