コード例 #1
0
ファイル: service.go プロジェクト: venicegeo/mpg-sandbox
func (registry *RegistryService) getServiceItem(w http.ResponseWriter, r *http.Request) {
	//log.Printf("getServiceItem")
	var err error
	var ok bool

	key := mux.Vars(r)["key"]

	var list *piazza.ServiceList

	if idInt, err := strconv.ParseInt(key, 10, 64); err == nil {
		id := piazza.PiazzaId(idInt)
		if list, ok = registry.table.LookupById(id); !ok {
			http.Error(w, "id not found", http.StatusBadRequest)
			return
		}
	} else {
		stype := piazza.ServiceTypeFromString(key)
		if stype == piazza.InvalidService {
			list = registry.table.LookupAll()
		} else if list, ok = registry.table.LookupByType(stype); !ok {
			http.Error(w, "service type not found", http.StatusBadRequest)
			return
		}
	}

	w.Header().Set("Content-Type", "application/json")

	buf, err := json.Marshal(list)
	if err != nil {
		http.Error(w, err.Error(), http.StatusBadRequest)
		return
	}

	w.Write(buf)
}
コード例 #2
0
ファイル: table.go プロジェクト: venicegeo/mpg-sandbox
func (t *serviceTable) LookupByTypeString(key string) (e *piazza.ServiceList, ok bool) {

	stype := piazza.ServiceTypeFromString(key)
	if stype == piazza.InvalidService {
		return nil, false
	}
	return t.LookupByType(stype)
}