本文整理匯總了Golang中github.com/GeoNet/weft.ServiceUnavailableError函數的典型用法代碼示例。如果您正苦於以下問題:Golang ServiceUnavailableError函數的具體用法?Golang ServiceUnavailableError怎麽用?Golang ServiceUnavailableError使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了ServiceUnavailableError函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: quakeProto
func quakeProto(r *http.Request, h http.Header, b *bytes.Buffer) *weft.Result {
if res := weft.CheckQuery(r, []string{}, []string{}); !res.Ok {
return res
}
var q haz.Quake
var res *weft.Result
if q.PublicID, res = getPublicIDPath(r); !res.Ok {
return res
}
var t time.Time
var mt time.Time
var err error
if err = db.QueryRow(quakeProtoSQL, q.PublicID).Scan(&t, &mt,
&q.Depth, &q.Magnitude, &q.Locality, &q.Mmi, &q.Quality,
&q.Longitude, &q.Latitude); err != nil {
return weft.ServiceUnavailableError(err)
}
q.Time = &haz.Timestamp{Sec: t.Unix(), Nsec: int64(t.Nanosecond())}
q.ModificationTime = &haz.Timestamp{Sec: mt.Unix(), Nsec: int64(mt.Nanosecond())}
var by []byte
if by, err = proto.Marshal(&q); err != nil {
return weft.ServiceUnavailableError(err)
}
b.Write(by)
h.Set("Content-Type", protobuf)
return &weft.StatusOK
}
示例2: quakeTechnicalProto
// fetches SC3ML and turns it into a protobuf.
func quakeTechnicalProto(r *http.Request, h http.Header, b *bytes.Buffer) *weft.Result {
if res := weft.CheckQuery(r, []string{}, []string{}); !res.Ok {
return res
}
by, res := getBytes(s3+strings.TrimPrefix(r.URL.Path, "/quake/technical/")+".xml", "")
if !res.Ok {
return res
}
q, err := sc3ml.QuakeTechnical(by)
if err != nil {
return weft.ServiceUnavailableError(err)
}
m, err := proto.Marshal(&q)
if err != nil {
return weft.ServiceUnavailableError(err)
}
b.Write(m)
h.Set("Content-Type", protobuf)
return &weft.StatusOK
}
示例3: newsProto
func newsProto(r *http.Request, h http.Header, b *bytes.Buffer) *weft.Result {
if res := weft.CheckQuery(r, []string{}, []string{}); !res.Ok {
return res
}
res, err := client.Get(newsURL)
defer res.Body.Close()
if err != nil {
return weft.ServiceUnavailableError(err)
}
body, err := ioutil.ReadAll(res.Body)
if err != nil {
return weft.ServiceUnavailableError(err)
}
f, err := unmarshalNews(body)
if err != nil {
return weft.ServiceUnavailableError(err)
}
var n haz.News
for _, v := range f.Entries {
s := haz.Story{
Title: v.Title,
Link: v.Link.Href,
}
t, err := time.Parse(time.RFC3339, v.Published)
if err != nil {
return weft.ServiceUnavailableError(err)
}
ts := haz.Timestamp{Sec: t.Unix(), Nsec: int64(t.Nanosecond())}
s.Published = &ts
n.Stories = append(n.Stories, &s)
}
var by []byte
if by, err = proto.Marshal(&n); err != nil {
return weft.ServiceUnavailableError(err)
}
b.Write(by)
h.Set("Content-Type", protobuf)
h.Set("Surrogate-Control", maxAge300)
return &weft.StatusOK
}
示例4: intensityProto
func intensityProto(r *http.Request, h http.Header, b *bytes.Buffer) *weft.Result {
if res := weft.CheckQuery(r, []string{"type"}, []string{"publicID"}); !res.Ok {
return res
}
var ts string
var err error
if ts, err = getIntensityType(r); err != nil {
return weft.BadRequest(err.Error())
}
var shaking *haz.Shaking
switch ts {
case "measured":
if shaking, err = intensityMeasuredLatest(); err != nil {
return weft.ServiceUnavailableError(err)
}
case "reported":
publicID := r.URL.Query().Get("publicID")
switch publicID {
case "":
end := time.Now().UTC()
start := end.Add(-60 * time.Minute)
if shaking, err = intensityReported(start, end); err != nil {
return weft.ServiceUnavailableError(err)
}
default:
var t time.Time
var res *weft.Result
if t, res = getQuakeTime(r); !res.Ok {
return res
}
start := t.Add(-1 * time.Minute)
end := t.Add(15 * time.Minute)
if shaking, err = intensityReported(start, end); err != nil {
return weft.ServiceUnavailableError(err)
}
}
}
var by []byte
if by, err = proto.Marshal(shaking); err != nil {
return weft.ServiceUnavailableError(err)
}
b.Write(by)
h.Set("Content-Type", protobuf)
return &weft.StatusOK
}
示例5: quakeHistoryProto
func quakeHistoryProto(r *http.Request, h http.Header, b *bytes.Buffer) *weft.Result {
if res := weft.CheckQuery(r, []string{}, []string{}); !res.Ok {
return res
}
var publicID string
var res *weft.Result
if publicID, res = getPublicIDHistoryPath(r); !res.Ok {
return res
}
var rows *sql.Rows
var err error
if rows, err = db.Query(quakeHistoryProtoSQL, publicID); err != nil {
return weft.ServiceUnavailableError(err)
}
var quakes []*haz.Quake
for rows.Next() {
var t time.Time
var mt time.Time
q := haz.Quake{PublicID: publicID}
if err = rows.Scan(&t, &mt, &q.Depth,
&q.Magnitude, &q.Locality, &q.Mmi, &q.Quality,
&q.Longitude, &q.Latitude); err != nil {
return weft.ServiceUnavailableError(err)
}
q.Time = &haz.Timestamp{Sec: t.Unix(), Nsec: int64(t.Nanosecond())}
q.ModificationTime = &haz.Timestamp{Sec: mt.Unix(), Nsec: int64(mt.Nanosecond())}
quakes = append(quakes, &q)
}
qs := haz.Quakes{Quakes: quakes}
var by []byte
if by, err = proto.Marshal(&qs); err != nil {
return weft.ServiceUnavailableError(err)
}
b.Write(by)
h.Set("Content-Type", protobuf)
return &weft.StatusOK
}
示例6: 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
}
示例7: 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
}
示例8: 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
}
示例9: 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
}
示例10: valV2
func valV2(r *http.Request, h http.Header, b *bytes.Buffer) *weft.Result {
if res := weft.CheckQuery(r, []string{}, []string{}); !res.Ok {
return res
}
var d string
err := db.QueryRow(`SELECT row_to_json(fc)
FROM ( SELECT 'FeatureCollection' as type, array_to_json(array_agg(f)) as features
FROM (SELECT 'Feature' as type,
ST_AsGeoJSON(v.location)::json as geometry,
row_to_json((SELECT l FROM
(
SELECT
id AS "volcanoID",
title AS "volcanoTitle",
alert_level as "level",
activity,
hazards
) as l
)) as properties FROM (haz.volcano JOIN haz.volcanic_alert_level using (alert_level)) as v ) As f ) as fc`).Scan(&d)
if err != nil {
return weft.ServiceUnavailableError(err)
}
b.WriteString(d)
h.Set("Content-Type", V2GeoJSON)
return &weft.StatusOK
}
示例11: quakesProto
func quakesProto(r *http.Request, h http.Header, b *bytes.Buffer) *weft.Result {
if res := weft.CheckQuery(r, []string{"MMI"}, []string{}); !res.Ok {
return res
}
var mmi int
var err error
if mmi, err = getMMI(r); err != nil {
return weft.BadRequest(err.Error())
}
var rows *sql.Rows
if rows, err = db.Query(quakesProtoSQL, mmi); err != nil {
return weft.ServiceUnavailableError(err)
}
var quakes haz.Quakes
for rows.Next() {
var t time.Time
var mt time.Time
var q haz.Quake
if err = rows.Scan(&q.PublicID, &t, &mt, &q.Depth,
&q.Magnitude, &q.Locality, &q.Mmi, &q.Quality,
&q.Longitude, &q.Latitude); err != nil {
return weft.ServiceUnavailableError(err)
}
q.Time = &haz.Timestamp{Sec: t.Unix(), Nsec: int64(t.Nanosecond())}
q.ModificationTime = &haz.Timestamp{Sec: mt.Unix(), Nsec: int64(mt.Nanosecond())}
quakes.Quakes = append(quakes.Quakes, &q)
}
var by []byte
if by, err = proto.Marshal(&quakes); err != nil {
return weft.ServiceUnavailableError(err)
}
b.Write(by)
h.Set("Content-Type", protobuf)
return &weft.StatusOK
}
示例12: fieldLatestGeoJSON
func fieldLatestGeoJSON(r *http.Request, h http.Header, b *bytes.Buffer) *weft.Result {
var rows *sql.Rows
var err error
typeID := r.URL.Query().Get("typeID")
var d string
err = db.QueryRow("select typeID FROM field.type where typeID = $1", typeID).Scan(&d)
if err == sql.ErrNoRows {
return &weft.NotFound
}
if err != nil {
return weft.ServiceUnavailableError(err)
}
if rows, err = dbR.Query(`
WITH p as (SELECT geom, time, value, lower, upper, deviceid, typeid
FROM field.metric_summary
JOIN field.device using (devicePK)
JOIN field.threshold using (devicePK, typePK)
JOIN field.type using (typePK)
WHERE typeID = $1)
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(p.geom)::json as geometry,
row_to_json(
(SELECT l FROM
(
SELECT
"time",
value,
lower,
upper,
deviceid,
typeid
) as l
)
) as properties FROM p
) as f ) as fc`, typeID); err != nil {
return weft.InternalServerError(err)
}
defer rows.Close()
var gj string
if rows.Next() {
if err = rows.Scan(&gj); err != nil {
return weft.InternalServerError(err)
}
}
rows.Close()
b.WriteString(gj)
return &weft.StatusOK
}
示例13: quakesRegionV1
func quakesRegionV1(r *http.Request, h http.Header, b *bytes.Buffer) *weft.Result {
if res := weft.CheckQuery(r, []string{"regionID", "regionIntensity", "number", "quality"}, []string{}); !res.Ok {
return res
}
var err error
if _, err = getRegionID(r); err != nil {
return weft.BadRequest(err.Error())
}
if _, err = getQuality(r); err != nil {
return weft.BadRequest(err.Error())
}
var regionIntensity string
if regionIntensity, err = getRegionIntensity(r); err != nil {
return weft.BadRequest(err.Error())
}
var n int
if n, err = getNumberQuakes(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(q.geom)::json as geometry,
row_to_json((SELECT l FROM
(
SELECT
publicid AS "publicID",
to_char(time, 'YYYY-MM-DD"T"HH24:MI:SS.MS"Z"') as "time",
depth,
magnitude,
locality,
intensity,
intensity_newzealand as "regionIntensity",
quality
) as l
)) as properties FROM haz.quakeapi as q where mmid_newzealand >= $1
ORDER BY time DESC limit $2 ) as f ) as fc`, int(msg.IntensityMMI(regionIntensity)), n).Scan(&d)
if err != nil {
return weft.ServiceUnavailableError(err)
}
b.WriteString(d)
h.Set("Content-Type", V1GeoJSON)
return &weft.StatusOK
}
示例14: feltV1
func feltV1(r *http.Request, h http.Header, b *bytes.Buffer) *weft.Result {
if res := weft.CheckQuery(r, []string{"publicID"}, []string{}); !res.Ok {
return res
}
var publicID string
var res *weft.Result
if publicID, res = getPublicID(r); !res.Ok {
return res
}
var rs *http.Response
rs, err := client.Get(feltURL + publicID + ".geojson")
defer rs.Body.Close()
if err != nil {
return weft.ServiceUnavailableError(err)
}
bt, err := ioutil.ReadAll(rs.Body)
if err != nil {
return weft.ServiceUnavailableError(err)
}
// Felt returns a 400 when it should probably be a 404. Tapestry quirk?
switch {
case http.StatusOK == rs.StatusCode:
h.Set("Content-Type", V1GeoJSON)
b.Write(bt)
return &weft.StatusOK
case 4 == rs.StatusCode/100:
//res := ¬Found
//res.msg = string(bt)
return &weft.NotFound
case 5 == rs.StatusCode/500:
return weft.ServiceUnavailableError(errors.New("error proxying felt resports. Shrug."))
}
return weft.ServiceUnavailableError(errors.New("unknown response from felt."))
}
示例15: valProto
func valProto(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 rows *sql.Rows
if rows, err = db.Query(`SELECT id, title, alert_level, activity, hazards,
ST_X(location::geometry), ST_Y(location::geometry)
FROM haz.volcano JOIN haz.volcanic_alert_level using (alert_level)
ORDER BY alert_level DESC, title ASC`); err != nil {
return weft.ServiceUnavailableError(err)
}
var vol haz.Volcanoes
for rows.Next() {
v := haz.Volcano{Val: &haz.VAL{}}
if err = rows.Scan(&v.VolcanoID, &v.Title, &v.Val.Level, &v.Val.Activity, &v.Val.Hazards,
&v.Longitude, &v.Latitude); err != nil {
return weft.ServiceUnavailableError(err)
}
vol.Volcanoes = append(vol.Volcanoes, &v)
}
var by []byte
if by, err = proto.Marshal(&vol); err != nil {
return weft.ServiceUnavailableError(err)
}
b.Write(by)
h.Set("Content-Type", protobuf)
return &weft.StatusOK
}