main.go 732 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")
14
15
	c := r.PathPrefix("/conservation/v1").Methods("GET").Subrouter()

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

	c.Path("/species/{speciesKey}").
25
		HandlerFunc(handler.Shandler)
26

27
	c.Path("/diag/").
28
		HandlerFunc(handler.Dhandler)
29

Aksel Baardsen's avatar
works    
Aksel Baardsen committed
30
	http.Handle("/", r)
31
	log.Fatal(http.ListenAndServe(":"+port, nil))
Aksel Baardsen's avatar
works    
Aksel Baardsen committed
32
}
Aksel Baardsen's avatar
fix  
Aksel Baardsen committed
33