main.go 740 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
14
15
16

	// sets port
	port := ""
	port = os.Getenv("PORT")
Aksel Baardsen's avatar
Aksel Baardsen committed
17
18
19
20
	if port == "" {
		port = "5000"
	}

Aksel Baardsen's avatar
Aksel Baardsen committed
21
	// creating a sub-router with a fixed path that only accepts GET-requests
22
23
	c := r.PathPrefix("/conservation/v1").Methods("GET").Subrouter()

Aksel Baardsen's avatar
Aksel Baardsen committed
24
	// one handler for each path
25
	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
Aksel Baardsen committed
34
	// makes sure that the router r handles all http-requests
Aksel Baardsen's avatar
works    
Aksel Baardsen committed
35
	http.Handle("/", r)
36
	log.Fatal(http.ListenAndServe(":"+port, nil))
Aksel Baardsen's avatar
works    
Aksel Baardsen committed
37
}
Aksel Baardsen's avatar
fix    
Aksel Baardsen committed
38