github.com/uvalib/orcid-access-ws@v0.0.0-20250612130209-7d062dbabf9d/orcidaccessws/handlers/search_orcid_handler.go (about) 1 package handlers 2 3 import ( 4 "net/http" 5 // "github.com/gorilla/mux" 6 //"fmt" 7 "github.com/uvalib/orcid-access-ws/orcidaccessws/authtoken" 8 "github.com/uvalib/orcid-access-ws/orcidaccessws/config" 9 //"github.com/uvalib/orcid-access-ws/orcidaccessws/logger" 10 //"github.com/uvalib/orcid-access-ws/orcidaccessws/orcid" 11 ) 12 13 const defaulsSearchStartIx = "0" 14 const defaultSearchMaxResults = "50" 15 16 // SearchOrcid -- the search orcid handler 17 func SearchOrcid(w http.ResponseWriter, r *http.Request) { 18 19 //vars := mux.Vars( r ) 20 query := r.URL.Query().Get("q") 21 token := r.URL.Query().Get("auth") 22 start := r.URL.Query().Get("start") 23 count := r.URL.Query().Get("max") 24 25 // parameters OK? 26 if isEmpty(query) || isEmpty(token) { 27 status := http.StatusBadRequest 28 encodeOrcidSearchResponse(w, status, http.StatusText(status), nil, 0, 0, 0) 29 return 30 } 31 32 // check the supplied parameters and set defaults as necessary 33 if isEmpty(start) { 34 start = defaulsSearchStartIx 35 } 36 if isEmpty(count) { 37 count = defaultSearchMaxResults 38 } 39 40 // validate parameters as necessary 41 if isNumeric(start) == false || isNumeric(count) == false { 42 status := http.StatusBadRequest 43 encodeOrcidSearchResponse(w, status, http.StatusText(status), nil, 0, 0, 0) 44 return 45 } 46 47 // validate the token 48 if authtoken.Validate(config.Configuration.SharedSecret, token) == false { 49 status := http.StatusForbidden 50 encodeOrcidSearchResponse(w, status, http.StatusText(status), nil, 0, 0, 0) 51 return 52 } 53 54 // 55 // not implemented as we have moved to the 2.0 API which supports different behavior 56 // 57 status := http.StatusNotImplemented 58 encodeOrcidSearchResponse(w, status, http.StatusText(status), nil, 0, 0, 0) 59 60 // get the ORCID details 61 //orcids, total, status, err := orcid.SearchOrcid(query, start, count) 62 63 // we got an error, return it 64 //if err != nil { 65 // encodeOrcidSearchResponse(w, status, 66 // fmt.Sprintf("%s (%s)", http.StatusText(status), err), nil, 0, 0, 0) 67 // return 68 //} 69 70 //logger.Log(fmt.Sprintf("INFO: ORCID search: %d result(s) located", len(orcids))) 71 72 // everything OK but found no items 73 //if len(orcids) == 0 { 74 // status = http.StatusNotFound 75 //} else { 76 // status = http.StatusOK 77 //} 78 79 //encodeOrcidSearchResponse(w, status, http.StatusText(status), orcids, asNumeric(start), len(orcids), total) 80 } 81 82 // 83 // end of file 84 //