main.go 769 Bytes
Newer Older
Aksel Baardsen's avatar
fix  
Aksel Baardsen committed
1
2
3
package main

import (
4
	"assignment-1/handler"
5
	"github.com/gorilla/mux"
6
	"log"
Aksel Baardsen's avatar
fix  
Aksel Baardsen committed
7
	"net/http"
Aksel Baardsen's avatar
Aksel Baardsen committed
8
	"os"
Aksel Baardsen's avatar
fix  
Aksel Baardsen committed
9
10
11
)

func main() {
Aksel Baardsen's avatar
works    
Aksel Baardsen committed
12
	r := mux.NewRouter()
Aksel Baardsen's avatar
Aksel Baardsen committed
13
	port := os.Getenv("PORT")
Aksel Baardsen's avatar
Aksel Baardsen committed
14
15
16
17
	if port == "" {
		port = "5000"
	}

18
19
	c := r.PathPrefix("/conservation/v1").Methods("GET").Subrouter()

20
	// two handlerpaths makes sure that the caller does not HAVE to specify limit
21
22
	c.Path("/country/{country_identifier:[a-zA-Z][a-zA-Z]}").
		Queries("limit", "{limit}").
23
		HandlerFunc(handler.Chandler).
24
25
		Name("Handel")
	c.Path("/country/{country_identifier:[a-zA-Z][a-zA-Z]}").
26
		HandlerFunc(handler.Chandler)
27
28

	c.Path("/species/{speciesKey}").
29
		HandlerFunc(handler.Shandler)
30

31
	c.Path("/diag/").
32
		HandlerFunc(handler.Dhandler)
33

Aksel Baardsen's avatar
works    
Aksel Baardsen committed
34
	http.Handle("/", r)
35
	log.Fatal(http.ListenAndServe(":"+port, nil))
Aksel Baardsen's avatar
works    
Aksel Baardsen committed
36
}
Aksel Baardsen's avatar
fix  
Aksel Baardsen committed
37