本文整理匯總了Golang中github.com/GeoNet/weft.CheckQuery函數的典型用法代碼示例。如果您正苦於以下問題:Golang CheckQuery函數的具體用法?Golang CheckQuery怎麽用?Golang CheckQuery使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了CheckQuery函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: fieldmetricsummaryHandler
func fieldmetricsummaryHandler(r *http.Request, h http.Header, b *bytes.Buffer) *weft.Result {
switch r.Method {
case "GET":
switch r.Header.Get("Accept") {
case "application/x-protobuf":
if res := weft.CheckQuery(r, []string{}, []string{"typeID"}); !res.Ok {
return res
}
h.Set("Content-Type", "application/x-protobuf")
return fieldLatestProto(r, h, b)
case "image/svg+xml":
if res := weft.CheckQuery(r, []string{"bbox", "typeID", "width"}, []string{}); !res.Ok {
return res
}
h.Set("Content-Type", "image/svg+xml")
return fieldLatestSvg(r, h, b)
case "application/vnd.geo+json":
if res := weft.CheckQuery(r, []string{"typeID"}, []string{}); !res.Ok {
return res
}
h.Set("Content-Type", "application/vnd.geo+json")
return fieldLatestGeoJSON(r, h, b)
default:
if res := weft.CheckQuery(r, []string{"bbox", "typeID", "width"}, []string{}); !res.Ok {
return res
}
h.Set("Content-Type", "image/svg+xml")
return fieldLatestSvg(r, h, b)
}
default:
return &weft.MethodNotAllowed
}
}
示例2: datacompletenessHandler
func datacompletenessHandler(r *http.Request, h http.Header, b *bytes.Buffer) *weft.Result {
switch r.Method {
case "GET":
switch r.Header.Get("Accept") {
case "image/svg+xml":
if res := weft.CheckQuery(r, []string{"siteID", "typeID"}, []string{"plot", "resolution", "yrange"}); !res.Ok {
return res
}
h.Set("Content-Type", "image/svg+xml")
return dataCompletenessSvg(r, h, b)
default:
if res := weft.CheckQuery(r, []string{"siteID", "typeID"}, []string{"plot", "resolution", "yrange"}); !res.Ok {
return res
}
h.Set("Content-Type", "image/svg+xml")
return dataCompletenessSvg(r, h, b)
}
case "PUT":
if res := weft.CheckQuery(r, []string{"count", "siteID", "time", "typeID"}, []string{}); !res.Ok {
return res
}
return dataCompletenessPut(r, h, b)
case "DELETE":
if res := weft.CheckQuery(r, []string{"siteID", "typeID"}, []string{}); !res.Ok {
return res
}
return dataCompletenessDelete(r, h, b)
default:
return &weft.MethodNotAllowed
}
}
示例3: tagsHandler
func tagsHandler(r *http.Request, h http.Header, b *bytes.Buffer) *weft.Result {
switch r.Method {
case "GET":
switch r.Header.Get("Accept") {
case "application/x-protobuf":
if res := weft.CheckQuery(r, []string{}, []string{}); !res.Ok {
return res
}
h.Set("Content-Type", "application/x-protobuf")
return tagProto(r, h, b)
default:
return &weft.NotAcceptable
}
case "PUT":
if res := weft.CheckQuery(r, []string{}, []string{}); !res.Ok {
return res
}
return tagPut(r, h, b)
case "DELETE":
if res := weft.CheckQuery(r, []string{}, []string{}); !res.Ok {
return res
}
return tagDelete(r, h, b)
default:
return &weft.MethodNotAllowed
}
}
示例4: fieldmetricthresholdHandler
func fieldmetricthresholdHandler(r *http.Request, h http.Header, b *bytes.Buffer) *weft.Result {
switch r.Method {
case "GET":
switch r.Header.Get("Accept") {
case "application/x-protobuf":
if res := weft.CheckQuery(r, []string{}, []string{}); !res.Ok {
return res
}
h.Set("Content-Type", "application/x-protobuf")
return fieldThresholdProto(r, h, b)
default:
return &weft.NotAcceptable
}
case "PUT":
if res := weft.CheckQuery(r, []string{"deviceID", "lower", "typeID", "upper"}, []string{}); !res.Ok {
return res
}
return fieldThresholdPut(r, h, b)
case "DELETE":
if res := weft.CheckQuery(r, []string{"deviceID", "typeID"}, []string{}); !res.Ok {
return res
}
return fieldThresholdDelete(r, h, b)
default:
return &weft.MethodNotAllowed
}
}
示例5: datacompletenesssummaryHandler
func datacompletenesssummaryHandler(r *http.Request, h http.Header, b *bytes.Buffer) *weft.Result {
switch r.Method {
case "GET":
switch r.Header.Get("Accept") {
case "image/svg+xml":
if res := weft.CheckQuery(r, []string{"bbox", "typeID", "width"}, []string{}); !res.Ok {
return res
}
h.Set("Content-Type", "image/svg+xml")
return dataCompletenessSummarySvg(r, h, b)
case "application/x-protobuf":
if res := weft.CheckQuery(r, []string{}, []string{"typeID"}); !res.Ok {
return res
}
h.Set("Content-Type", "application/x-protobuf")
return dataCompletenessSummaryProto(r, h, b)
default:
if res := weft.CheckQuery(r, []string{"bbox", "typeID", "width"}, []string{}); !res.Ok {
return res
}
h.Set("Content-Type", "image/svg+xml")
return dataCompletenessSummarySvg(r, h, b)
}
default:
return &weft.MethodNotAllowed
}
}
示例6: appmetricHandler
func appmetricHandler(r *http.Request, h http.Header, b *bytes.Buffer) *weft.Result {
switch r.Method {
case "GET":
switch r.Header.Get("Accept") {
case "image/svg+xml":
if res := weft.CheckQuery(r, []string{"applicationID", "group"}, []string{"resolution", "sourceID", "yrange"}); !res.Ok {
return res
}
h.Set("Content-Type", "image/svg+xml")
return appMetricSvg(r, h, b)
case "text/csv":
if res := weft.CheckQuery(r, []string{"applicationID", "group"}, []string{"endDate", "resolution", "sourceID", "startDate"}); !res.Ok {
return res
}
h.Set("Content-Type", "text/csv")
return appMetricCsv(r, h, b)
default:
if res := weft.CheckQuery(r, []string{"applicationID", "group"}, []string{"resolution", "sourceID", "yrange"}); !res.Ok {
return res
}
h.Set("Content-Type", "image/svg+xml")
return appMetricSvg(r, h, b)
}
default:
return &weft.MethodNotAllowed
}
}
示例7: quakesWWWnz
func quakesWWWnz(r *http.Request, h http.Header, b *bytes.Buffer) *weft.Result {
if res := weft.CheckQuery(r, []string{}, []string{}); !res.Ok {
return res
}
path := r.URL.Path[quakesNZServiceLen:] // ..."3/100.json"
tokens := strings.Split(path, "/")
if len(tokens) != 2 {
return weft.BadRequest("Bad URL path.")
}
var mmi int
var err error
var count int
if mmi, err = strconv.Atoi(tokens[0]); err != nil {
return weft.BadRequest("Bad URL path. Invalid mmi.")
}
if count, err = strconv.Atoi(tokens[1][:len(tokens[1])-5]); err != nil { // len(".json")
return weft.BadRequest("Bad URL path. Invalid count.")
}
var d string
err = db.QueryRow(quakesNZWWWSQL, mmi, count).Scan(&d)
if err != nil {
return weft.ServiceUnavailableError(err)
}
b.WriteString(d)
h.Set("Content-Type", JSON)
return &weft.StatusOK
}
示例8: metricDetailHandler
// handler that serves an html page for detailed metric information
func metricDetailHandler(r *http.Request, h http.Header, b *bytes.Buffer) *weft.Result {
var (
err error
)
if res := weft.CheckQuery(r, []string{"deviceID", "typeID"}, []string{}); !res.Ok {
return res
}
// We create a page struct with variables to substitute into the loaded template
q := r.URL.Query()
deviceID := q.Get("deviceID")
typeID := q.Get("typeID")
p := metricDetailPage{MtrApiUrl: mtrApiUrl}
p.Border.Title = fmt.Sprintf("Detailed Metric Info for deviceID:%s TypeID:%s", deviceID, typeID)
p.MetricDetail.DeviceID = deviceID
p.MetricDetail.TypeID = typeID
if err = p.populateTags(); err != nil {
return weft.InternalServerError(err)
}
if err = metricDetailTemplate.ExecuteTemplate(b, "border", p); err != nil {
return weft.InternalServerError(err)
}
return &weft.StatusOK
}
示例9: home
func home(r *http.Request, h http.Header, b *bytes.Buffer) *weft.Result {
if res := weft.CheckQuery(r, []string{}, []string{}); !res.Ok {
return res
}
return &weft.NotFound
}
示例10: fieldPageHandler
func fieldPageHandler(r *http.Request, h http.Header, b *bytes.Buffer) *weft.Result {
var err error
if res := weft.CheckQuery(r, []string{}, []string{}); !res.Ok {
return res
}
p := mtrUiPage{}
p.Path = r.URL.Path
p.Border.Title = "GeoNet MTR"
p.ActiveTab = "Field"
if err = p.populateTags(); err != nil {
return weft.InternalServerError(err)
}
var pa panel
if pa, err = getFieldSummary(); err != nil {
return weft.InternalServerError(err)
}
p.Panels = []panel{pa}
if err = fieldTemplate.ExecuteTemplate(b, "border", p); err != nil {
return weft.InternalServerError(err)
}
return &weft.StatusOK
}
示例11: sensorV2
// Proxies sensor *.geojson from S3
func sensorV2(r *http.Request, h http.Header, b *bytes.Buffer) *weft.Result {
if res := weft.CheckQuery(r, []string{"type"}, []string{}); !res.Ok {
return res
}
t := r.URL.Query().Get("type")
if !sensorGeoJSON[t] {
return &weft.NotFound
}
params := &s3.GetObjectInput{
Key: aws.String("delta/" + t + ".geojson"),
Bucket: aws.String("api.geonet.org.nz"),
}
res, err := s3Client.GetObject(params)
if err != nil {
return weft.InternalServerError(err)
}
defer res.Body.Close()
_, err = b.ReadFrom(res.Body)
if err != nil {
return weft.InternalServerError(err)
}
h.Set("Content-Type", V2GeoJSON)
h.Set("Surrogate-Control", maxAge3600)
return &weft.StatusOK
}
示例12: intensityMeasuredLatestV1
func intensityMeasuredLatestV1(r *http.Request, h http.Header, b *bytes.Buffer) *weft.Result {
if res := weft.CheckQuery(r, []string{"type"}, []string{}); !res.Ok {
return res
}
if r.URL.Query().Get("type") != "measured" {
return weft.BadRequest("type must be measured.")
}
var d string
err := db.QueryRow(
`SELECT row_to_json(fc)
FROM ( SELECT 'FeatureCollection' as type, COALESCE(array_to_json(array_agg(f)), '[]') as features
FROM (SELECT 'Feature' as type,
ST_AsGeoJSON(s.location)::json as geometry,
row_to_json(( select l from
(
select mmi
) as l ))
as properties from (select location, mmi
FROM impact.intensity_measured) as s
) As f ) as fc`).Scan(&d)
if err != nil {
return weft.ServiceUnavailableError(err)
}
b.WriteString(d)
h.Set("Content-Type", V1GeoJSON)
return &weft.StatusOK
}
示例13: volcanoRegionV2
func volcanoRegionV2(r *http.Request, h http.Header, b *bytes.Buffer) *weft.Result {
if res := weft.CheckQuery(r, []string{}, []string{}); !res.Ok {
return res
}
var err error
var volcanoId string
if volcanoId, err = getVolcanoIDRegion(r); err != nil {
return weft.BadRequest(err.Error())
}
var d string
err = db.QueryRow(`SELECT row_to_json(fc)
FROM ( SELECT 'FeatureCollection' as type, COALESCE(array_to_json(array_agg(f)), '[]') as features
FROM (SELECT 'Feature' as type,
ST_AsGeoJSON(r.region)::json as geometry,
row_to_json((SELECT l FROM
(
SELECT id,
title
) as l
)) as properties
FROM haz.volcano as r
where id = $1) as f ) as fc;`, volcanoId).Scan(&d)
if err != nil {
return weft.ServiceUnavailableError(err)
}
b.WriteString(d)
h.Set("Content-Type", V2GeoJSON)
return &weft.StatusOK
}
示例14: quakeV2
func quakeV2(r *http.Request, h http.Header, b *bytes.Buffer) *weft.Result {
if res := weft.CheckQuery(r, []string{}, []string{}); !res.Ok {
return res
}
if len(r.URL.Query()) != 0 {
return weft.BadRequest("incorrect number of query parameters.")
}
var publicID string
var res *weft.Result
if publicID, res = getPublicIDPath(r); !res.Ok {
return res
}
var d string
err := db.QueryRow(quakeV2SQL, publicID).Scan(&d)
if err != nil {
return weft.ServiceUnavailableError(err)
}
b.WriteString(d)
h.Set("Content-Type", V2GeoJSON)
return &weft.StatusOK
}
示例15: dataSitesPageHandler
func dataSitesPageHandler(r *http.Request, h http.Header, b *bytes.Buffer) *weft.Result {
var err error
if res := weft.CheckQuery(r, []string{}, []string{"status", "typeID"}); !res.Ok {
return res
}
p := mtrUiPage{}
p.Path = r.URL.Path
p.Border.Title = "GeoNet MTR - Data Sites"
p.ActiveTab = "Data"
p.MtrApiUrl = mtrApiUrl.String()
if err = p.populateTags(); err != nil {
return weft.InternalServerError(err)
}
p.pageParam(r.URL.Query())
if err = p.getSitesList(); err != nil {
return weft.InternalServerError(err)
}
if err = dataTemplate.ExecuteTemplate(b, "border", p); err != nil {
return weft.InternalServerError(err)
}
return &weft.StatusOK
}