Developers’ Weblog

Sponsored by
HostEurope Logo

Developers’ Weblog

All 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30

Quick! A webserver!

04.01.2012 by bsiegert@
Tags: golang tip

If, like me, you occasionally want to transfer some files via http—like the sets for a MirOS installation—but are much too lazy to set up apache, here is a simple web server in nine lines of Go:

	package main

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

	func main() {
		Handle("/", FileServer(Dir(".")))
		log.Fatal(ListenAndServe(":8080", nil))
	}

It simply exports the current directory via http on port 8080. Neat!

MirOS Logo