Skip to content

Instantly share code, notes, and snippets.

@junaidrahim
Last active March 18, 2020 07:35
Show Gist options
  • Save junaidrahim/d26db940fd36a8e36caebfb26d3117bb to your computer and use it in GitHub Desktop.
Save junaidrahim/d26db940fd36a8e36caebfb26d3117bb to your computer and use it in GitHub Desktop.
API Example
package main
import (
"fmt"
"log"
"net/http"
)
func handler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hi there")
}
func main() {
fmt.Println("Starting server on port 3000")
// run the handler function when a request
// to the "/" endpoint is made
http.HandleFunc("/", handler)
log.Fatal(http.ListenAndServe(":3000", nil)) // start the server
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment