/
method.go
54 lines (44 loc) · 1.31 KB
/
method.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package main
import (
"bytes"
"github.com/GeoNet/fits/internal/valid"
"github.com/GeoNet/kit/weft"
"net/http"
)
func method(r *http.Request, h http.Header, b *bytes.Buffer) error {
q, err := weft.CheckQueryValid(r, []string{"GET"}, []string{}, []string{"typeID"}, valid.Query)
if err != nil {
return err
}
h.Set("Content-Type", "application/json;version=1")
typeID := q.Get("typeID")
if typeID != "" {
err = validType(typeID)
if err != nil {
return err
}
}
var d string
switch typeID {
case "":
err = db.QueryRow(
`select row_to_json(fc) from (select array_to_json(array_agg(m)) as method
from (select methodid as "methodID", method.name, method.description, method.reference
from
fits.type join fits.type_method using (typepk)
join fits.method using (methodpk)) as m) as fc`).Scan(&d)
default:
err = db.QueryRow(
`select row_to_json(fc) from (select array_to_json(array_agg(m)) as method
from (select methodid as "methodID", method.name, method.description, method.reference
from
fits.type join fits.type_method using (typepk)
join fits.method using (methodpk)
where type.typeID = $1) as m) as fc`, typeID).Scan(&d)
}
if err != nil {
return err
}
b.WriteString(d)
return nil
}