Exemple #1
0
func (a *analyser) GetAN003Data(request *restful.Request, response *restful.Response) {

	id := request.PathParameter("id")

	var reply []interface{}
	var err error

	rcon := a.pool.Get()
	defer rcon.Close()

	reply, err = redis.Values(rcon.Do("LRANGE", an003+":"+id, 0, -1))

	if err != nil {
		response.WriteError(http.StatusInternalServerError, err)
		return
	}

	var responseset []URLCheckRecord
	var s string

	for len(reply) > 0 {
		if reply, err = redis.Scan(reply, &s); err != nil {
			response.WriteError(http.StatusInternalServerError, err)
			return
		}
		var item URLCheckRecord
		if err := json.Unmarshal([]byte(s), &item); err != nil {
			response.WriteError(http.StatusInternalServerError, err)
			return
		}

		responseset = append(responseset, item)
	}
	response.WriteEntity(responseset)
}
Exemple #2
0
func (a *analyser) GetCheckResult(request *restful.Request, response *restful.Response) {

	id := request.PathParameter("id")

	var reply []interface{}
	var err error

	rcon := a.pool.Get()
	defer rcon.Close()

	reply, err = redis.Values(rcon.Do("HMGET", checkkey+":"+id, "CheckStatus", "CKANID", "Hittime"))
	if err != nil {
		response.WriteError(http.StatusInternalServerError, err)
		return
	}
	if len(reply) == 0 {
		response.WriteError(http.StatusInternalServerError, fmt.Errorf("Record not found"))
		return
	}

	var (
		CKANID  string
		Hittime string
		Status  string
	)

	if _, err = redis.Scan(reply, &Status, &CKANID, &Hittime); err != nil {
		response.WriteError(http.StatusInternalServerError, err)
		return
	}

	var checkStatus []CheckStatus
	checkrecord := CheckRecord{CKANID: CKANID}
	if len(Status) > 0 {

		if err := json.Unmarshal([]byte(Status), &checkStatus); err != nil {
			response.WriteError(http.StatusInternalServerError, err)
			return
		}
		checkrecord.CheckStatus = checkStatus
	}
	if len(Hittime) > 0 {
		hittime, err := time.Parse(RedigoTimestamp, Hittime)
		if err != nil {
			response.WriteError(http.StatusInternalServerError, err)
			return
		}
		checkrecord.Hittime = hittime
	}

	response.WriteEntity(checkrecord)
}
Exemple #3
0
func (a *analyser) GetTaxonomyDatasets(request *restful.Request, response *restful.Response) {

	taxonomy := request.PathParameter("which")
	subset := request.PathParameter("subset")

	var reply []interface{}
	var err error

	rcon := a.pool.Get()
	defer rcon.Close()

	type internalDataset struct {
		ID, CKANID  string
		Publisher   string
		Contact     string
		Description string
		Version     string
		Category    string
		GeoBBox     string
		GeoToponym  string
	}
	var internalsets []internalDataset
	reply, err = redis.Values(rcon.Do("SORT", datasetskey+":"+taxonomy+":"+subset,
		"BY", "nosort",
		"GET", datasetkey+":*->ID",
		"GET", datasetkey+":*->CKANID",
		"GET", datasetkey+":*->Publisher",
		"GET", datasetkey+":*->Contact",
		"GET", datasetkey+":*->Description",
		"GET", datasetkey+":*->Version",
		"GET", datasetkey+":*->Category",
		"GET", datasetkey+":*->GeoBBox",
		"GET", datasetkey+":*->GeoToponym"))
	if err != nil {
		response.WriteError(http.StatusInternalServerError, err)
		return
	}
	if err = redis.ScanSlice(reply, &internalsets); err != nil {
		response.WriteError(http.StatusInternalServerError, err)
		return
	}

	var responseset []Dataset
	for _, is := range internalsets {
		ds := Dataset{ID: is.ID,
			CKANID:      is.CKANID,
			Publisher:   is.Publisher,
			Contact:     is.Contact,
			Description: is.Description,
			Version:     is.Version,
			GeoBBox:     is.GeoBBox,
			GeoToponym:  is.GeoToponym}

		var strcats []string
		if len(is.Category) > 0 {
			if err := json.Unmarshal([]byte(is.Category), &strcats); err != nil {
				response.WriteError(http.StatusInternalServerError, err)
				return
			}
		}
		ds.Category = strcats
		responseset = append(responseset, ds)
	}
	response.WriteEntity(responseset)
}
Exemple #4
0
func (a *analyser) GetDataset(request *restful.Request, response *restful.Response) {

	id := request.PathParameter("id")

	var reply []interface{}
	var err error

	rcon := a.pool.Get()
	defer rcon.Close()

	reply, err = redis.Values(rcon.Do("HMGET", datasetkey+":"+id,
		"ID",
		"CKANID",
		"Publisher",
		"Contact",
		"Description",
		"Version",
		"Category",
		"GeoBBox",
		"GeoToponym"))
	if err != nil {
		response.WriteError(http.StatusInternalServerError, err)
		return
	}
	if len(reply) == 0 {
		response.WriteError(http.StatusInternalServerError, fmt.Errorf("Record not found"))
		return
	}

	var (
		ID, CKANID  string
		Publisher   string
		Contact     string
		Description string
		Version     string
		Category    string
		GeoBBox     string
		GeoToponym  string
	)

	if _, err = redis.Scan(reply,
		&ID,
		&CKANID,
		&Publisher,
		&Contact,
		&Description,
		&Version,
		&Category,
		&GeoBBox,
		&GeoToponym); err != nil {
		response.WriteError(http.StatusInternalServerError, err)
		return
	}

	ds := Dataset{ID: ID,
		CKANID:      CKANID,
		Publisher:   Publisher,
		Contact:     Contact,
		Description: Description,
		Version:     Version,
		GeoBBox:     GeoBBox,
		GeoToponym:  GeoToponym}

	if len(Category) > 0 {
		var strcats []string
		if err := json.Unmarshal([]byte(Category), &strcats); err != nil {
			response.WriteError(http.StatusInternalServerError, err)
			return
		}
		ds.Category = strcats
	}

	response.WriteEntity(ds)
}