Government Security
Network Security Resources

Jump to content


Make A Basic Go Http Server

- - - - - security server php
  • Please log in to reply
No replies to this topic

#1 Stephen


    Commander In Chief

  • GSO Management
  • 1,808 posts

Posted 01 August 2010 - 11:37 PM

If you’ve read any of the Go Documentation there are a couple of examples of howto use “http” package. In particular if you’ve read the Effective Go Doc there’s an example that’s very similar to this implementation.

Starting with the Boilerplate example we need to add an import for “http” and add a couple of line to func main. to end up with the following :

package main

import (

func main(){
	fmt.Printf("Starting http Server ... ")
	http.Handle("/", http.HandlerFunc(sayHello))
	err := http.ListenAndServe("", nil)
	if err != nil {
		fmt.Printf("ListenAndServe Error :" + err.String())

func sayHello(c *http.Conn, req *http.Request) {
	fmt.Printf("New Request\n")
	c.Write([]byte("<h1>Go Say's Hello</h1><h2>(Via http)</h2>"))

Posted Image

Also tagged with one or more of these keywords: security, server, php