Skip to content
Snippets Groups Projects
Select Git revision
  • e68f38d87274ccf8a7becd364447e48baa9c76d1
  • master default protected
  • 69-resize-image-before-upload
  • 60-add-match-salamander-modal-to-edit-salamander
  • 50-fix-server-error-message
  • 48-fix-gradle
  • 31-camera-communicate-with-api-and-delete-from-cache-2
  • 20-changing-verification-step-in-profile-to-modal
  • 4-add-all-basic-views
  • 1-setup
10 results

CustomButton.js

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    country.go 781 B
    package handler
    
    import (
    	"assignment-1/pkg"
    	"encoding/json"
    	"github.com/gorilla/mux"
    	"log"
    	"net/http"
    )
    
    // handles requests for /country/
    func Chandler(w http.ResponseWriter, r *http.Request) {
    	vars := mux.Vars(r)
    	limit := r.FormValue("limit") // gets the limit, if specified
    
    	// unnecessary default limit (gbif API has default of 20)
    	if len(limit) == 0 {
    		limit = "5"
    	}
    
    	// gets a country-struct containing data, or error
    	country, err := pkg.GetCountryByCode(vars["country_identifier"], limit)
    
    	if err == nil {
    		w.Header().Set("Content-Type", "application/json")
    		err = json.NewEncoder(w).Encode(&country)
    		if err != nil {
    			log.Fatal(err)
    		}
    	} else {
    		// need to check error for content when setting header (pkg.CorrectHeader)
    		pkg.HttpError(w, err)
    	}
    }