github.com/go-spatial/go-wfs@v0.1.4-0.20190401000911-c9fba2bb5188/server/routes.go (about)

     1  ///////////////////////////////////////////////////////////////////////////////
     2  //
     3  // The MIT License (MIT)
     4  // Copyright (c) 2018 Jivan Amara
     5  // Copyright (c) 2018 Tom Kralidis
     6  //
     7  // Permission is hereby granted, free of charge, to any person obtaining a copy
     8  // of this software and associated documentation files (the "Software"), to
     9  // deal in the Software without restriction, including without limitation the
    10  // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
    11  // sell copies of the Software, and to permit persons to whom the Software is
    12  // furnished to do so, subject to the following conditions:
    13  //
    14  // The above copyright notice and this permission notice shall be included in
    15  // all copies or substantial portions of the Software.
    16  //
    17  // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
    18  // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
    19  // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
    20  // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
    21  // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
    22  // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
    23  // USE OR OTHER DEALINGS IN THE SOFTWARE.
    24  //
    25  ///////////////////////////////////////////////////////////////////////////////
    26  
    27  package server
    28  
    29  // Provides mappings for URL routes to handler functions.
    30  
    31  import (
    32  	"net/http"
    33  
    34  	"github.com/julienschmidt/httprouter"
    35  	"github.com/rs/cors"
    36  )
    37  
    38  func setUpRoutes() http.Handler {
    39  	r := httprouter.New()
    40  	c := cors.New(cors.Options{
    41  		AllowedMethods: []string{"GET", "HEAD"},
    42  	})
    43  
    44  	r.Handler("GET", "/", c.Handler(http.HandlerFunc(root)))
    45  	r.Handler("HEAD", "/", c.Handler(http.HandlerFunc(root)))
    46  	r.Handler("GET", "/conformance", c.Handler(http.HandlerFunc(conformance)))
    47  	r.Handler("HEAD", "/conformance", c.Handler(http.HandlerFunc(conformance)))
    48  	r.Handler("GET", "/api", c.Handler(http.HandlerFunc(openapi)))
    49  	r.Handler("HEAD", "/api", c.Handler(http.HandlerFunc(openapi)))
    50  
    51  	r.Handler("GET", "/collections", c.Handler(http.HandlerFunc(collectionsMetaData)))
    52  	r.Handler("HEAD", "/collections", c.Handler(http.HandlerFunc(collectionsMetaData)))
    53  	r.Handler("GET", "/collections/:name", c.Handler(http.HandlerFunc(collectionMetaData)))
    54  	r.Handler("HEAD", "/collections/:name", c.Handler(http.HandlerFunc(collectionMetaData)))
    55  	r.Handler("GET", "/collections/:name/items", c.Handler(http.HandlerFunc(collectionData)))
    56  	r.Handler("HEAD", "/collections/:name/items", c.Handler(http.HandlerFunc(collectionData)))
    57  	r.Handler("GET", "/collections/:name/items/:feature_id", c.Handler(http.HandlerFunc(collectionData)))
    58  	r.Handler("HEAD", "/collections/:name/items/:feature_id", c.Handler(http.HandlerFunc(collectionData)))
    59  
    60  	return r
    61  }