Skip to content

Instantly share code, notes, and snippets.

@adigunhammedolalekan
Created May 3, 2018 12:04
Show Gist options
  • Save adigunhammedolalekan/aa058266ca5dc3f4658569cdfc77f3fd to your computer and use it in GitHub Desktop.
Save adigunhammedolalekan/aa058266ca5dc3f4658569cdfc77f3fd to your computer and use it in GitHub Desktop.
package main
import (
"github.com/gorilla/mux"
"go-contacts/app"
"os"
"fmt"
"net/http"
)
func main() {
router := mux.NewRouter()
router.Use(app.JwtAuthentication) //attach JWT auth middleware
port := os.Getenv("PORT") //Get port from .env file, we did not specify any port so this should return an empty string when tested locally
if port == "" {
port = "8000" //localhost
}
fmt.Println(port)
err := http.ListenAndServe(":" + port, router) //Launch the app, visit localhost:8000/api
if err != nil {
fmt.Print(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment