Elements. Build native projects for any modern development platform, using the language(s) of your choice. Oxygene (Object Pascal), C#, Swift, Java, Go. | RemObjects Software

TinyHTTPServer

Language: Gold, Platform: Island, Category: macOS
https://github.com/remobjects/ElementsSamples/tree/master/Gold/Island/macOS/TinyHTTPServer

  • TinyHTTPServer
    • References
      • gc
      • Island
      • Go
      • rtl
    • Source Files
    • Other Files

Program.go

package TinyHTTPServer

// http server, with a handler for '/hello' path
// to test just browse to http://127.0.0.1:6789/hello

import (
	"net/http"
	"log"
)

// function to handle /hello path, in this case showing "This is an example server"
func HelloServer(w http.ResponseWriter, req *http.Request) {
	w.Header().Set("Content-Type", "text/plain")
	w.Write([]byte("This is an example server.\n"))
}

func main() {
	// add handler func HelloServer for "/hello" path
	http.HandleFunc("/hello", HelloServer)
	// listen on 6789 port
	err := http.ListenAndServe(":6789", nil);

	if err != nil {
		log.Fatal("ListenAndServe: ", err)
	}
}