Skip to content

Instantly share code, notes, and snippets.

@mikebuss
Created January 27, 2020 23:54
Show Gist options
  • Save mikebuss/051cf5a6d6227e2d2fc592f56926dabc to your computer and use it in GitHub Desktop.
Save mikebuss/051cf5a6d6227e2d2fc592f56926dabc to your computer and use it in GitHub Desktop.
Simple Go Server
package main
import (
"fmt"
"net/http"
"io/ioutil"
)
func main() {
http.HandleFunc("/devices", HandleDeviceRequest)
http.ListenAndServe(":8080", nil)
}
func HandleDeviceRequest(w http.ResponseWriter, r *http.Request) {
data, err := ioutil.ReadFile("/var/lib/misc/dnsmasq.leases")
if err != nil {
fmt.Println("Unable to read dnsmasq.leases file", err)
return
}
fmt.Printf("Response: %s", string(data))
w.Write(data)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment