ML
    • Recent
    • Categories
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    Directory Server in Go

    IT Discussion
    golang go webserver
    1
    1
    687
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • stacksofplatesS
      stacksofplates
      last edited by

      I've been spending time learning Go and here's a small utility I wrote that's similar to Python's SimpleHTTPServer.

      package main
      
      import (
      	"log"
      	"net/http"
      	"os"
      )
      
      func main() {
      	if len(os.Args) < 2 {
      		log.Fatal("You must enter a path")
      	}
      	path := os.Args[1]
      
      	http.Handle("/", http.FileServer(http.Dir(path)))
      	http.ListenAndServe(":8000", nil)
      }
      

      This creates an HTTP server serving all of the files in the path you specify.

      Just use this:

      go run serve.go /etc
      

      Or do go build serve.go and it will create a binary you can run.

      0_1514152098917_http.png

      1 Reply Last reply Reply Quote 1
      • 1 / 1
      • First post
        Last post