Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions Golang/Get Api in Golang
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package main

import (
// Import the gorilla/mux library we just installed
"fmt"
"net/http"

"github.com/gorilla/mux"
)

func main() {
// Declare a new router
r := mux.NewRouter()

// This is where the router is useful, it allows us to declare methods that
// this path will be valid for
r.HandleFunc("/hello", handler).Methods("GET")

// We can then pass our router (after declaring all our routes) to this method
// (where previously, we were leaving the second argument as nil)
http.ListenAndServe(":8080", r)
}

func handler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello World!")
}